【发布时间】:2014-07-04 10:18:28
【问题描述】:
我的目标是代表我的网络应用用户对 Google Fusion Tables 进行最简单的查询。为此,我在 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"
}'
我用谷歌搜索了几天,大多数答案都在谈论刷新令牌。我进行了这次刷新,但仍然出现同样的错误!
有解决这个问题的想法吗? 谢谢
【问题讨论】:
标签: php symfony google-fusion-tables google-api-php-client service-accounts