我正在尝试获取 OAuth 访问令牌以将一些数据导入融合表。我正在尝试使用 Google API PHP 客户端。我为此创建了一个服务帐户,并且正在使用代码,主要来自serviceAccount示例:
function access_token()
{
$client = new Google_Client();
$client->setAuthClass ('Google_OAuth2');
// ^ Don't know if this line is required,
// ^ but it fails just as well without it.
$client->setApplicationName ('Mysite.dom.ain');
$client->setAssertionCredentials (new Google_AssertionCredentials
( 'MANY-NUMBERS-LETTERS-DASHES@developer.gserviceaccount.com',
array ('https://www.googleapis.com/auth/fusiontables'),
file_get_contents ('path/to/my/privatekey.p12') ));
$client->setClientId ('NUMBERS-LETTERS-DASHES.apps.googleusercontent.com');
$client->authenticate();
// ^ Also fails equally good with and without this line.
return $client->getAccessToken();
}
一点调试输出显示$client->authenticate()
返回true
,但$client->getAcessToken()
返回null
。不抛出异常。我觉得我在做一些根本错误的事情。如果是这样,请原谅我的愚蠢并指出我正确的方向。