2

我没有运气调用 Google+ API 来推送CommentActivity时刻。我已经能够成功推送AddActivity以及DiscoverActivity

我在互联网上的某处阅读,同时搜索 400 HTTP 状态表示我的用户凭据无效的解决方案,但在尝试 CommentActivity 后我已经能够发布 AddActivity 和 DiscoverActivity 并且我尝试断开并重新连接我的帐户并链接所需的凭证无济于事。

这是我生成时刻的代码,我相信这是错误,这可能与在此时刻类型中使用目标和结果有关(DiscoverActivity 和 AddActivity 都没有 Result 字段)。特别是,Target 和 Result 的 URL 相同,但 Result 有一个附加的锚点。但是,文档暗示这应该可以正常工作。

  $moment = new Google_Moment();
  $moment->setType("http://schemas.google.com/CommentActivity");
  $target = new Google_ItemScope();
  $target->setUrl(get_permalink($comment->comment_post_id));
  $target->setType("http://schema.org/Article");
  $moment->setTarget($target);
  $result = new Google_ItemScope();
  $result->setId("comment-".$comment_id);
  $result->setType("http://schema.org/Comment");
  $result->setUrl(get_comment_link($comment_id));
  $result->setText($comment->comment_content);
  $moment->setResult($result);
  Soci_Base::getSocial("google")->getUser($user)->GPlus->moments->insert('me', 'vault', $moment);

GPlus 是对 Google_PlusService 对象的引用。

这是我收到的堆栈跟踪异常(省略了文件的无意义部分,hooks.php 和 plugin.php 不是 Google+ API)

致命错误:未捕获的异常 'Google_ServiceException' 和消息'调用 POST 时出错https://www.googleapis.com/plus/v1/people/me/moments/vault?key=AIzaSyBa27u5PtBgFHO4SY_Fq9_0sO39pFWrRzE : (400) Invalid Value' in /~/ src/io/Google_REST.php:66 堆栈跟踪:#0 /~/G+/src/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 /~/G+/src/service /Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 /~/G+/src/contrib/Google_PlusService.php(167): Google_ServiceResource->__call('insert', Array) #3 / ~/hooks.php(54): Google_MomentsServiceResource->insert('me', 'vault', Object(Google_Moment)) #4 /~/plugin.php(406): soci_comment('108040') #5 /~ 在/~/lib/G+/src/io/Google_REST.php在第66行

我认为这就是我在这件事上的所有信息——我不知道要获得脚本发出的确切 HTTP 请求。预先感谢您的任何和所有帮助,甚至看看^_^

这是整个登录序列的代码:

Soci_Google::addActionRequirement('http://schemas.google.com/AddActivity');
Soci_Google::addActionRequirement('http://schemas.google.com/CommentActivity');
Soci_Google::addActionRequirement('http://schemas.google.com/CreateActivity');
Soci_Google::addActionRequirement('http://schemas.google.com/DiscoverActivity');

Soci_Google::addActionRequirement:

public static function addActionRequirement($url) {
    self::$activities[] = $url;
}

self::$token 只是对字符串的引用

$ret = new Soci_Google();
self::$users[$id] = $ret;
$ret->setToken(self::$meta->getMeta($user, self::$token));
return $ret;

Soci_Google __construct():

public function __construct() {
    $this->googleObj = new Google_Client();
    $this->googleObj->setApplicationName(self::$appName);
    $this->googleObj->setClientId(self::$clientID);
    $this->googleObj->setClientSecret(self::$clientSecret);
    $this->googleObj->setRedirectUri(self::$redirectURI);
    $this->googleObj->setDeveloperKey(self::$devKey);
    $this->GPlus = new Google_PlusService($this->googleObj);
    $this->googleObj->setRequestVisibleActions(self::$activities);
}

Soci_Goolge setToken

$this->googleObj->setAccessToken($googleUsrToken);
4

0 回答 0