In my google plus add an action using the Google+ Domains API and PHP. I get an error

This is my code to insert the activity:

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);

 ....................

      

And I get the ERROR:

Fatal error: Throw exception "Google_Service_Exception" with message "Failed to call 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 Stack trace: # 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-> execute (object (Google_Http_Request)) # 3 / var / www / html / public / pruebas _sociales / google-api / src / Google / Service / PlusDomains.php (491): Google_Service_Resource-> call (' insert ', Array,' Google_Service _... ')

4 / var / www / html / public / pruebas_sociales / google-api / examples / idtoken.php (114):

Google_Service_PlusDomains_Activities_ in / var / www / html / public / pruebas _sociales / google-api / src / Google / Http / REST.php on line 79

I have a problem two weeks ago. How can I fix this? Reference.

+3


source to share





All Articles