How to delete a YouTube video using cURL

非 Y 不嫁゛ 提交于 2020-01-16 00:49:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!