我正试图在PHP中使用google client作为一个项目。在这篇声明中,我得到了“拒绝许可”的回应:
$client->getAuth()->refreshTokenWithAssertion();
/home/www/blah.com/restful/libs/Google/IO/Curl.php,消息:未能连接到74.125.193.84:权限拒绝文件: /home/www/blah.com/restful/libs/Google/IO/Abstract.php(125):Google_IO_Curl->executeRequest(Object(Google_Http_Request))行:81 Google_IO_Exception #1 /home/www/blah.com/restful/libs/Google/Auth/OAuth2.php(326):Google_IO_Abstract->makeRequest(Object(Google_Http_Request)) #2 /home/www/blah.com/restful/libs/Google/Auth/OAuth2.php(306):Google_Auth_OAuth2->refreshTokenRequest(Array) #3 /home/www/blah.com/restful/v2/index.php(122):Google_Auth_OAuth2->refreshTokenWithAssertion()
我检查了我所有的证件,他们看上去是正确的,有什么问题吗?
谢谢,约翰
代码:
$client_id = '1234blahblahblah.apps.googleusercontent.com'; //Client ID
$service_account_name = '1234blahblah@developer.gserviceaccount.com'; //Email Address
$key_file_location = 'blahblah-1234.p12'; //key.p12
$client = new Google_Client();
$client->setApplicationName("test");
$service = new Google_Service_Calendar($client);
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/calendar'),
$key
);
print_r($cred);
$client->setAssertionCredentials($cred);
$client->setClientId($client_id);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion(); //<<<<<failed here.
}
$_SESSION['service_token'] = $client->getAccessToken();
echo $_SESSION['service_token'];
}
发布于 2014-10-07 09:26:02
嗨,约翰,我也遇到了同样的问题,最后这件事对我来说很管用:
在台词前:
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion(); //<<<<<failed here.
}
我放置了一个try catch,返回给我我有一个写操作权限问题:
try {
$client->getAuth()->refreshTokenWithAssertion($cred);
} catch (Exception $e) {
var_dump($e->getMessage());
}
我可以做两件事:
1)转到Google/src/Config.php并更改第94行:‘=>’sys_get_temp_dir()。‘/Google_Client’并更改目录以保存缓存临时文件
)或者像我一样,做了一个echo sys_get_temp_dir();在尝试捕获之前,并给这个dir一个chmod 777许可。
这个解决方案对我有用,我希望也对你有用。无论如何,尝试/捕捉等待异常消息
发布于 2014-10-03 17:26:34
请参阅Google客户端库的service-account.php目录中Github.com上的Github.com示例:
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred); // set credentials there
}
https://stackoverflow.com/questions/26098107
复制相似问题