环境详细信息
操作系统:Ubuntu 20
PHP版本:7.3.33
包名称和版本:api客户端v2.12.1/21.0/2.9.2
复制步骤
在从谷歌使用auth code
重定向到callback url
后,我试图通过调用fetchAccessTokenWithAuthCode('auth code')
使用auth代码获取access token
,但它被卡住了,之后什么都没有。它基本上返回一个request timeout
,因为即使在05分钟后谷歌也没有返回任何响应。
代码示例
$client = new GoogleClient;
$client->setApplicationName("CM");
$client->setScopes(Google_Service_Sheets::SPREADSHEETS_READONLY);
$client->setAuthConfig('client_secret.json');
if ($_GET['code']) {
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
$client->setAccessToken($token);
// Check to see if there was an error.
if (array_key_exists('error', $token)) {
throw new Exception(join(', ', $token));
}
}
谢谢!
问题似乎是我的ISP阻止了Google API URL。现在已经解决了。