我正在尝试通过 PHP 脚本在我的 Googleplus 业务页面上发布片刻。
要调用 Google API,我使用的是服务帐户。
下面的代码给出了这个错误“致命错误:在(最后一行)中的非对象上调用成员函数插入()”......你能帮我解决这个问题吗?
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);