0

PHP スクリプトを使用して Googleplus ビジネス ページにモーメントを投稿しようとしています。

Google API を呼び出すには、サービス アカウントを使用しています。

次のコードは、このエラー「致命的なエラー: (最後の行) の非オブジェクトでのメンバー関数 insert() の呼び出し」を返します....この問題を解決するのを手伝ってもらえますか?

require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_PlusService.php';

// Set your client id, service account name, and the path to your private key.
// For more information about obtaining these keys, visit:
// https://developers.google.com/console/help/#service_accountsconst CLIENT_ID = 'MYID';
const SERVICE_ACCOUNT_NAME = 'MYACCOUNT';

// Make sure you keep your key.p12 file in a secure location, and isn't
// readable by others.
const KEY_FILE = 'MYAUTHFILE';

// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$client = new Google_Client();

$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(SERVICE_ACCOUNT_NAME,array('https://www.googleapis.com/auth/prediction'),$key));


// Create moment that does not have a URL.
$item_scope = new Google_ItemScope();
$item_scope->setId("MYGOOGLEPAGEID");
$item_scope->setType("http://schemas.google.com/AddActivity");
$item_scope->setName("The Google+ Platform");
$item_scope->setDescription("A page that describes just how awesome Google+ is!");
$item_scope->setImage("https://developers.google.com/+/plugins/snippet/examples/thing.png");

$moment_body = new Google_Moment();
$moment_body->setType("http://schemas.google.com/AddActivity");
$moment_body->setTarget($item_scope);
$momentResult = $plus->moments->insert('me', 'vault', $moment_body);
4

2 に答える 2

1

Plus API Client を初期化していないようです:

$plus = new Google_PlusService($client);

https://www.googleapis.com/auth/plus.loginまた、代わりに正しいスコープを使用する必要がありますhttps://www.googleapis.com/auth/prediction

また、モーメントの書き込みがサービス アカウントで機能するかどうかはわかりません...

于 2013-06-05T14:14:04.380 に答える