1

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経由でトランクから取得しました。ありがとう。

4

1 に答える 1

0

openssl_sign()PHPのドキュメントによると、4番目のパラメーターはintである必要があります。

http://php.net/manual/en/function.openssl-sign.php

bool openssl_sign ( string $data , string &$signature , mixed $priv_key_id [, int $signature_alg = OPENSSL_ALGO_SHA1 ] )

Google_P12Signerのコードでは、次のように使用しています。

if (!openssl_sign($data, $signature, $this->privateKey, "sha256")) {
  throw new Google_AuthException("Unable to sign data");
}

明らかにINTではない「sha256」を渡す。これに従ってsha256用に定義されたOPENSSL_ALGO_*はありません: http ://www.php.net/manual/en/openssl.signature-algos.phpこれは機能しないことを意味します。

あなたがしなければならないことはあなた自身のOPENSSL_ALGO_SHA256を定義することです、あなたがこのコードで見るようなものです:http: //pastebin.com/qdCyC0Pe

誰かが役立つパッチを書きました:http://php.it2y.info/missing-sha256-sha512-families-of-signature-algorithms.html

于 2012-08-07T17:54:23.457 に答える