6
ここにあるクライアントライブラリを使用して、次のPHPコードを実行しています:https://code.google.com/p/google-api-php-client/。私はこのコードのいずれかのエラーを取得しませんが、getAccessToken()
を呼び出すと、nullを返します。サービスアカウントを使用して、getAccessToken()がnullを返す
私は自分のカレンダーでこのサービスアカウントにアクセスでき、APIコンソール経由でプロジェクトに完全にアクセスできました。
アイデア?何らかの理由で
require_once 'google-api-php-client/src/Google_Client.php';
const CLIENT_ID = 'blahblahblah';
const SERVICE_ACCOUNT_NAME = '[email protected]';
const KEY_FILE = 'path/to/privatekey.p12';
$google_client = new Google_Client(); // created only to initialized static dependencies
$client = new Google_OAuth2(); // you really just need Google_OAuth2
$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(
new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/calendar'),
$key
)
);
var_dump($client->getAccessToken());
どちらかわかりません。私はあなたのコードをhttps://gist.github.com/fulldecent/6728257で信用していますが、参考までにsetSCopesの行は不要です –
'' getAccessToken() ''はあなたが呼び出すまで存在しない現在のアクセストークンを返します'' refreshTokenWithAssertion() ''(初期化する)または '' setAccessToken() ''(あなたが使いたい以前のアクセストークンを回復した場合) – tiho