doulanli6146 2014-09-23 22:38
浏览 84

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

This is my code to insert an 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: Uncaught exception 'Google_Service_Exception' with message 'Error calling 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'm with the problem from two weeks ago. How I can fix it? Help.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集