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