这是我插入活动的代码:
const SERVICE_ACCOUNT_EMAIL = "xxxxxx";
const KEY_FILE = 'key.p12';
$client_id = 'yyyyyyyyy';
$client_secret = 'zzzzzzzzz';
$redirect_uri = 'ttttttttt';
$client = new Google_Client();
$client->setApplicationName("Prueba_social123");
$key = file_get_contents(KEY_FILE);
$user_credentials = new Google_Auth_AssertionCredentials(
SERVICE_ACCOUNT_EMAIL,
array("https://www.googleapis.com/auth/plus.me",
"https://www.googleapis.com/auth/plus.stream.write"),
$key);
$user_credentials->sub = "xxxxxxxxx@gmail.com";
$client->setAssertionCredentials($user_credentials);
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->setDeveloperKey('wwwwwwwwwwwwwwwwwwwwww');
$client->setScopes(array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/plus.stream.write') );
$plus = new Google_Service_Plus($client);
$oauth2 = new Google_Service_Oauth2($client);
if (isset($_REQUEST['logout'])) {
unset($_SESSION['access_token']);
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
} else {
$authUrl = $client->createAuthUrl();
}
if ($client->getAccessToken()) {
$_SESSION['access_token'] = $client->getAccessToken();
$token_data = $client->verifyIdToken()->getAttributes();
$plusdomains = new Google_Service_PlusDomains($client);
$activityObject = new Google_Service_PlusDomains_ActivityObject();
$activityObject->setOriginalContent("Prueba de actividad desde la API de mensajes123");
$activityAccess = new Google_Service_PlusDomains_Acl();
$activityAccess->setDomainRestricted(true);
$resource = new Google_Service_PlusDomains_PlusDomainsAclentryResource();
$resource->setType("public");
$resources = array();
$resources[] = $resource;
$activityAccess->setItems($resources);
$activity = new Google_Service_PlusDomains_Activity();
$activity->setObject($activityObject);
$activity->setAccess($activityAccess);
$plusdomains->activities->insert("me", $activity);
....................
我得到了错误:
致命错误:未捕获的异常“Google_Service_Exception”和消息“调用 POST 时出错 https://www.googleapis.com/plusDomains/v1/people/me/activities?key=xxxxxxxxxxxxxxxx: (403) Forbidden' in /var/www/html/public/pruebas_sociales/google-api/src/Google/Http/REST.php:79 堆栈跟踪:#0 /var/www/html/public/pruebas_sociales/google -api/src/Google/Http/REST.php(44): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request)) #1 /var/www/html/public/pruebas_sociales/google-api/src/Google/Client.php (512): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request)) #2 /var/www/html/public/pruebas_sociales/google-api/src/Google/Service/Resource.php(195): Google_Client ->执行(对象(Google_Http_Request))#3 /var/www/html/public/pruebas_sociales/google-api/src/Google/Service/PlusDomains.php(491):Google_Service_Resource->call('插入',数组, 'Google_Service_...')
4 /var/www/html/public/pruebas_sociales/google-api/examples/idtoken.php(114):
第 79 行 /var/www/html/public/pruebas_sociales/google-api/src/Google/Http/REST.php 中的 Google_Service_PlusDomains_Activities_
我从两周前就遇到了这个问题。我该如何解决?帮助。