我正在使用谷歌数据 PHP API。我关注https://developers.google.com/youtube/2.0/developers_guide_php#AuthSub_for_Web_Applications,希望我保留刷新令牌,并发送请求以获取访问令牌。刷新令牌适用于拥有视频的用户(我已使用 Java 完成此操作)。但最后我仍然无法通过身份验证。这里有什么问题?代码如下。
$refreshToken = '1/wY9.......';
$postString = 'client_id=' . $_SESSION['clientId'] .
'&client_secret=' . $_SESSION['clientSecret'] .
'&refresh_token=' . $refreshToken .
'&grant_type=refresh_token';
$ch = curl_init($_SESSION['oauth2Url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
$result = curl_exec($ch);
curl_close($ch);
$json = json_decode($result);
$accessToken = $json->access_token;
$httpClient = Zend_Gdata_AuthSub::getHttpClient($accessToken);
$yt = new Zend_Gdata_YouTube($httpClient, null, $_SESSION['clientId'], $_SESSION['developerKey']);
$yt->setMajorProtocolVersion(2);
$youtubeId = 'xxxxxxxxxxx';
$videoEntry = $yt->getVideoEntry($youtubeId);
if ($videoEntry->getEditLink() !== null) {
echo 'can edit!';
} else {
echo 'cannot edit!';
}
* 更新 *
正如其他人建议的那样,我尝试var_dump($httpClient)
了,并得到以下信息:
object(Zend_Gdata_HttpClient)#1 (23) {
["_authSubPrivateKeyId":"Zend_Gdata_HttpClient":private]=> NULL
["_authSubToken":"Zend_Gdata_HttpClient":private]=> string(61) "yaXXXXX"
["_clientLoginToken":"Zend_Gdata_HttpClient":private]=> NULL
["_clientLoginKey":"Zend_Gdata_HttpClient":private]=> NULL
["_streamingRequest":protected]=> NULL
["config":protected]=> array(12) {
["maxredirects"]=> int(5)
["strictredirects"]=> bool(true)
["useragent"]=> string(28) "Zend_Framework_Gdata/1.11.12"
["timeout"]=> int(10)
["adapter"]=> string(31) "Zend_Http_Client_Adapter_Socket"
["httpversion"]=> string(3) "1.1"
["keepalive"]=> bool(false)
["storeresponse"]=> bool(true)
["strict"]=> bool(true)
["output_stream"]=> bool(false)
["encodecookies"]=> bool(true)
["rfc3986_strict"]=> bool(false)
}
["adapter":protected]=> NULL
["uri":protected]=> NULL
["headers":protected]=> array(0) { }
["method":protected]=> string(3) "GET"
["paramsGet":protected]=> array(0) { }
["paramsPost":protected]=> array(0) { }
["enctype":protected]=> NULL
["raw_post_data":protected]=> NULL
["auth":protected]=> NULL
["files":protected]=> array(0) { }
["body_field_order":protected]=> array(0) { }
["cookiejar":protected]=> NULL
["last_request":protected]=> NULL
["last_response":protected]=> NULL
["redirectCounter":protected]=> int(0)
["_unmaskStatus":protected]=> bool(false)
["_queryBracketsEscaped":protected]=> bool(true)
}