フュージョンテーブルにデータをインポートするためにOAuthアクセストークンを取得しようとしています。GoogleAPIPHPクライアントを使用しようとしています。その目的のためにサービスアカウントを作成し、主に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
。例外はスローされません。根本的に間違ったことをしているような気がします。もしそうなら、私の愚かさを許し、正しい方向に私を向けてください。