微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐