加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何在PHP cURL中提供Youtube身份验证令牌

发布时间:2020-12-13 16:24:08 所属栏目:PHP教程 来源:网络整理
导读:在 this指南之后,我正在尝试检索Youtube用户的订阅.我能够获得用户的身份验证令牌,但是我不知道如何使用我的cURL请求实际发送它.文档只是这样说: To request a feed of the currently logged-in user’s subscriptions, send a GET request to the followin
在 this指南之后,我正在尝试检索Youtube用户的订阅.我能够获得用户的身份验证令牌,但是我不知道如何使用我的cURL请求实际发送它.文档只是这样说:

To request a feed of the currently logged-in user’s subscriptions,
send a GET request to the following URL. Note: For this request,you
must provide an authorization token,which enables YouTube to verify
that the user authorized access to the resource.

07001

当我发送没有令牌的请求时,我得到401用户身份验证所需的错误.我找不到有关如何发送令牌的任何信息.这是我目前的代码:

$ch_subs = curl_init();
curl_setopt($ch_subs,CURLOPT_URL,'https://gdata.youtube.com/feeds/api/users/default/subscriptions?v=2');
curl_setopt($ch_subs,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch_subs,CURLOPT_SSL_VERIFYPEER,false);
$subs_return = curl_exec($ch_subs);
curl_close($ch_subs);

在此先感谢您的帮助.

看看本指南:

https://developers.google.com/youtube/2.0/developers_guide_protocol#OAuth2_Calling_a_Google_API

您需要添加一个包含以下内容的标头:Authorization:Bearer ACCESS_TOKEN

$headers = array('Authorization: Bearer ' . $access_token);
curl_setopt($ch_subs,CURLOPT_HTTPHEADER,$headers);

您还可以将令牌作为Get请求的一部分传递:

curl_setopt($ch_subs,'https://gdata.youtube.com/feeds/api/users/default/subscriptions?v=2&access_token=' . $access_token);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读