gpt4 book ai didi

google-oauth - refreshTokenWithAssertion 权限被拒绝

转载 作者:行者123 更新时间:2023-12-04 06:17:08 25 4
gpt4 key购买 nike

我正在尝试在 PHP 中使用 google-api-client 进行项目。
在此声明中,我收到了“权限被拒绝”的回复:

$client->getAuth()->refreshTokenWithAssertion();

Google_IO_Exception, Message:Failed to connect to 74.125.193.84: Permission denied File: /home/www/blah.com/restful/libs/Google/IO/Curl.php Line:81 /home/www/blah.com/restful/libs/Google/IO/Abstract.php(125): Google_IO_Curl->executeRequest(Object(Google_Http_Request))

#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'];
}

最佳答案

嗨约翰我有同样的问题,最后这对我有用:

行前:

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 行: 'directory' => sys_get_temp_dir() 。 '/Google_Client' 并更改目录以保存缓存临时文件

2) 或者像我一样,做了一个 echo sys_get_temp_dir();在 try catch 之前,给那个目录一个 chmod 777 权限

这个解决方案对我有用,我也希望对你有用。无论如何做了一个 try/catch 等待异常消息

关于google-oauth - refreshTokenWithAssertion 权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26098107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com