OATH2 を使用して Google アナリティクス API (v3) に対して認証しようとすると、次のエラーが発生します。
警告: openssl_sign() は、パラメーター 4 が長いことを想定しています。文字列は google-api-php-client/src/auth/Google_P12Signer.php の 60 行目に指定されています
Google_AuthException: 行 61 で google-api-php-client/src/auth/Google_P12Signer.php のデータに署名できません
これが私のPHPコードです:
// api dependencies
require_once(dirname(__FILE__) . '/../../vendor/google-api-php-client/src/Google_Client.php');
require_once(dirname(__FILE__) . '/../../vendor/google-api-php-client/src/contrib/Google_AnalyticsService.php');
session_start();
// create client object and set app name
$client = new Google_Client();
$client->setApplicationName(APP_NAME);
// set assertion credentials
$client->setAssertionCredentials(
new Google_AssertionCredentials(
'xxxxxxx@developer.gserviceaccount.com',
array('https://www.googleapis.com/auth/analytics.readonly'),
file_get_contents('xxxxxxxxxx-privatekey.p12') // keyfile
));
// other settings
$client->setClientId('xxxxxxx.apps.googleusercontent.com');
$client->setAccessType('offline_access');
// create service
$service = new Google_AnalyticsService($client);
$properties = $service->management_webproperties->listManagementWebproperties("~all");
print_r($properties);
print_r($service) の場合、エラーのない有効なオブジェクトが得られます。エラーを生成するのは listManagementWebproperties() 呼び出しです。
誰か解決策を教えてください。ほんの数日前に編集されたので、Google_Client は流動的である可能性があります。サービスアカウントをサポートしていない古いバージョンがあると思われるダウンロードページではなく、SVN経由でトランクから取得しました。ありがとう。