PHP谷歌YouTube API认证

PHP谷歌YouTube API认证,php,authentication,oauth,youtube,google-api,Php,Authentication,Oauth,Youtube,Google Api,我使用的是谷歌数据PHP API。我遵循,希望保留一个刷新令牌,并发送请求以获取访问令牌。刷新令牌是为拥有视频的用户提供的(我使用Java实现了这一点)。但最终我还是无法被认证。这里怎么了?代码如下 $refreshToken = '1/wY9.......'; $postString = 'client_id=' . $_SESSION['clientId'] . '&client_secret=' . $_SESSION['clientSecret'] .

我使用的是谷歌数据PHP API。我遵循,希望保留一个刷新令牌,并发送请求以获取访问令牌。刷新令牌是为拥有视频的用户提供的(我使用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\u 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)
} 

最后,我知道发生了什么


身份验证实际上已经完成。但是不要使用
$videoEntry->getEditLink()
测试服务是否经过身份验证。Zend PHP库非常古老。也许新的数据结构没有编辑链接。

您是否尝试过通过放置一些
var_dump()
调用来调试它?@TomvanderWoerdt在
$httpClient
之前,我得到了所需的一切。那么就无法知道
$httpClient
是否经过身份验证。