我的目标是进行最简单的查询Google Fusion Tables
代表我的网络应用程序用户。为此,我创建了一个服务帐户在谷歌控制台上。这是代码:
// Creating a google client
$client = new \Google_Client();
// setting the service acount credentials
$serviceAccountName = 'XXXXX.apps.googleusercontent.com';
$scopes= array(
'https://www.googleapis.com/auth/fusiontables',
'https://www.googleapis.com/auth/fusiontables.readonly',
);
$privateKey=file_get_contents('/path/to/privatekey.p12');
$privateKeyPassword='notasecret'; // the default one when generated in the console
$credential = new \Google_Auth_AssertionCredentials($serviceAccountName,
$scopes, $privateKey, $privateKeyPassword);
// setting assertion credentials
$client->setAssertionCredentials($credential);
$service = new \Google_Service_Fusiontables($client);
$sql = 'select name from XXXXXXXX';
$result = $service->query->sql($sql);
运行此代码后,我收到此错误:
Error refreshing the OAuth2 token, message: '{
"error" : "invalid_grant"
}'
我用谷歌搜索了好几天,大多数答案都在谈论刷新令牌。我做了这个刷新但仍然是同样的错误!
有解决这个问题的想法吗?
谢谢
就我而言,这是由于服务器时间相差太远(大约5分钟)造成的。
虽然您的问题已经解决,但也许这对将来登陆这里的人有任何帮助,因为 Google 返回的错误是相同的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)