在我的google plus中使用“Domains Google+ API”和PHP插入活动。我收到错误

时间:2014-09-23 22:38:18

标签: php google-api google-plus google-domain-api

这是我插入活动的代码:

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)禁止'在   /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(对象(Google_Http_Request))#1   /var/www/html/public/pruebas_sociales/google-api/src/Google/Client.php(512):   Google_Http_REST ::执行(对象(Google_Client)   对象(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->电话('插入',数组,' 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   第79行

两周前我遇到了这个问题。我该怎么办呢?帮助

0 个答案:

没有答案