我的目标是Google Fusion Tables
代表我的Web应用程序用户进行最简单的查询。为此,我在Google控制台上创建了一个服务帐户。这是代码:
// 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"
}'
我用谷歌搜索了好几天,大多数答案都在谈论刷新令牌。我做了刷新,但仍然是相同的错误!
有解决这个问题的主意吗?谢谢
我知道许多人都面临着与我相同的问题。因此,这是在Google上搜索几天后的解决方案。
我提出的代码只有一个错误:客户端ID类似于电子邮件,类似于 [email protected]
您要做的第二件事是与服务帐户的客户ID共享您在google融合表中查询的表。
在那之后,事情将完美地进行。
我希望这会帮助其他人。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句