如何使用cURL删除YouTube视频 [英] How to delete a YouTube video using cURL

查看:277
本文介绍了如何使用cURL删除YouTube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向YouTube API发出DELETE请求,但当我回应 curl_getinfo($ ch,CURLINFO_HTTP_CODE)时,它只是说0,这意味着它失败。



我已经检查了我的API密钥,这是正确的,所以访问代码,因为我获得访问令牌使用刷新令牌。

$ b $

  $ url = b 

cURL命令是正确的还是应该查看访问代码? 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);


解决方案

我这样做:

  $ 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包含所有的refresh_access标记,所以我使用substr函数来获取access_token。



在var $ url中,你可以看到比我退出的MY_API_KEY部分,因为没有必要。它只适用于access_token



希望我帮助你。


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);

解决方案

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.

这篇关于如何使用cURL删除YouTube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆