Google Plus PHP API - 插入时刻不起作用

时间:2013-04-14 13:56:42

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

我想与google plus分享我的状态。

我关注了谷歌api,但我收到了未经授权的错误。我试图修复它超过2天,但我不能..

我读了这个答案,我下载并测试了api,仍然不适合我。

401 Unauthorized access when posting Google+ Moments with PHP Client

你可以在这里查看,

https://code.google.com/p/google-api-php-client/source/browse/trunk/examples/moments/simple.php

在这个主干文件中,他们仍在调用Google_PlusMomentsService.php

我尝试了以下代码,但仍无效 - https://developers.google.com/+/api/latest/moments/insert

这是我正在测试的实时链接:http://webscarlets.in/projects/babblesuite/gplus/index.php

这是我用来分享状态的代码

 $target = new Google_ItemScope();
 $target->url = 'https://developers.google.com/+/plugins/snippet/examples/thing';


  $moment = new Google_Moment();
  $moment->type = "http://schemas.google.com/AddActivity";
  $moment->target = $target;

  // Execute the request
  $moments->moments->insert('me', 'vault', $moment);
  print '<p>Created an AddActivity moment</p>';

任何人都可以解决它。

感谢所有

1 个答案:

答案 0 :(得分:3)

您需要在PHP客户端中授权用户并请求可见操作(例如AddActivity),然后才能将应用程序活动写入用户的配置文件。因为您使用的是较旧的示例,所以您可能无法在按钮或OAuth2流程中设置requestvisibleactions。

从这里开始尝试: https://developers.google.com/+/quickstart/php

这是最新的PHP启动程序,已经过验证可行。如果您确实想要使用您共享的旧代码,请分享登录按钮标记,例如:

<span id="signinButton">
  <span
    class="g-signin"
    data-callback="signinCallback"
    data-clientid="CLIENT_ID"
    data-cookiepolicy="single_host_origin"
    data-requestvisibleactions="http://schemas.google.com/AddActivity"
    data-scope="https://www.googleapis.com/auth/plus.login">
  </span>
</span>

因为我猜你错过了这一行:data-requestvisibleactions ...