问题
I am trying to make a DELETE request to the YouTube API but when I echo out curl_getinfo($ch, CURLINFO_HTTP_CODE)
, it just says 0 which mean it failed.
I have checked my API key and that's correct and so is the access code as i'm getting an access token using the refresh token.
Is the cURL commands correct or should i be looking at the access code?
$url = "https://www.googleapis.com/youtube/v3/videos?id=".$vID."MY_API_KEY";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-type: application/json','Authorization : Bearer '.$access_token));
$result = curl_exec ($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
回答1:
I do this:
$token = substr($key, 17, 83);
$url = "https://www.googleapis.com/youtube/v3/videos?id=".$video_id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-type: application/json','Authorization : Bearer '.$token));
curl_exec ($ch);
curl_close ($ch);
$key contains all my refresh_access token so I use substr function to get just the access_token.
In the var $url you can see than I quit ."MY_API_KEY" part because is not necessary. It works fine only with the access_token
Hope I help you.
来源:https://stackoverflow.com/questions/26482760/how-to-delete-a-youtube-video-using-curl