{"id":3010,"date":"2014-03-13T11:20:54","date_gmt":"2014-03-13T11:20:54","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/13\/google-api-commentactivity-return-400-error-collection-of-common-programming-errors\/"},"modified":"2014-03-13T11:20:54","modified_gmt":"2014-03-13T11:20:54","slug":"google-api-commentactivity-return-400-error-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/13\/google-api-commentactivity-return-400-error-collection-of-common-programming-errors\/","title":{"rendered":"Google+ API CommentActivity return 400 Error-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m having no luck calling the Google+ API for pushing a CommentActivity moment. I have been able to push an AddActivity successfully as well as a DiscoverActivity.<\/p>\n<p>I read somewhere on the internet whilst searching for a solution that the 400 HTTP Status represents that my user credentials are invalid, but I have been able to post AddActivity &amp; DiscoverActivity after trying CommentActivity and I have tried disconnecting and reconnecting my account and linking the required credentials to no avail.<\/p>\n<p>Here&#8217;s my code to generate the moment, I believe this is the error, and it&#8217;s probably something to do with the use of a Target and a Result in this moment type (Neither DiscoverActivity nor AddActivity have a Result field). In particular, the Target&#8217;s and Result&#8217;s URLs are the same but the Result&#8217;s has an appended anchor. The documentation implies that this should work fine, however.<\/p>\n<pre><code>  $moment = new Google_Moment();\n  $moment-&gt;setType(\"http:\/\/schemas.google.com\/CommentActivity\");\n  $target = new Google_ItemScope();\n  $target-&gt;setUrl(get_permalink($comment-&gt;comment_post_id));\n  $target-&gt;setType(\"http:\/\/schema.org\/Article\");\n  $moment-&gt;setTarget($target);\n  $result = new Google_ItemScope();\n  $result-&gt;setId(\"comment-\".$comment_id);\n  $result-&gt;setType(\"http:\/\/schema.org\/Comment\");\n  $result-&gt;setUrl(get_comment_link($comment_id));\n  $result-&gt;setText($comment-&gt;comment_content);\n  $moment-&gt;setResult($result);\n  Soci_Base::getSocial(\"google\")-&gt;getUser($user)-&gt;GPlus-&gt;moments-&gt;insert('me', 'vault', $moment);\n<\/code><\/pre>\n<p>GPlus is a reference to a Google_PlusService object.<\/p>\n<p>Here&#8217;s my exception I receive with stack trace (Pointless parts of the files are omitted, hooks.php and plugin.php are not the Google+ API)<\/p>\n<pre><code>**Fatal error**:  Uncaught exception 'Google_ServiceException' with message 'Error calling 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 Stack trace:\n#0 \/~\/G+\/src\/io\/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest))\n#1 \/~\/G+\/src\/service\/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest))\n#2 \/~\/G+\/src\/contrib\/Google_PlusService.php(167): Google_ServiceResource-&gt;__call('insert', Array)\n#3 \/~\/hooks.php(54): Google_MomentsServiceResource-&gt;insert('me', 'vault', Object(Google_Moment))\n#4 \/~\/plugin.php(406): soci_comment('108040')\n#5 \/~ in <b>\/~\/lib\/G+\/src\/io\/Google_REST.php<\/b> on line <b>66<\/b><br \/>\n<\/code><\/pre>\n<p>I think that&#8217;s all of the info I have on the matter &#8211; I have no idea to get the exact HTTP request the script makes. Thank you in advance for any and all help and for even having a look ^_^<\/p>\n<p>Here&#8217;s the code for the whole login sequence:<\/p>\n<pre><code>Soci_Google::addActionRequirement('http:\/\/schemas.google.com\/AddActivity');\nSoci_Google::addActionRequirement('http:\/\/schemas.google.com\/CommentActivity');\nSoci_Google::addActionRequirement('http:\/\/schemas.google.com\/CreateActivity');\nSoci_Google::addActionRequirement('http:\/\/schemas.google.com\/DiscoverActivity');\n<\/code><\/pre>\n<p>Soci_Google::addActionRequirement:<\/p>\n<pre><code>public static function addActionRequirement($url) {\n    self::$activities[] = $url;\n}\n<\/code><\/pre>\n<p>self::$token is just a reference to a string<\/p>\n<pre><code>$ret = new Soci_Google();\nself::$users[$id] = $ret;\n$ret-&gt;setToken(self::$meta-&gt;getMeta($user, self::$token));\nreturn $ret;\n<\/code><\/pre>\n<p>Soci_Google __construct():<\/p>\n<pre><code>public function __construct() {\n    $this-&gt;googleObj = new Google_Client();\n    $this-&gt;googleObj-&gt;setApplicationName(self::$appName);\n    $this-&gt;googleObj-&gt;setClientId(self::$clientID);\n    $this-&gt;googleObj-&gt;setClientSecret(self::$clientSecret);\n    $this-&gt;googleObj-&gt;setRedirectUri(self::$redirectURI);\n    $this-&gt;googleObj-&gt;setDeveloperKey(self::$devKey);\n    $this-&gt;GPlus = new Google_PlusService($this-&gt;googleObj);\n    $this-&gt;googleObj-&gt;setRequestVisibleActions(self::$activities);\n}\n<\/code><\/pre>\n<p>Soci_Goolge setToken<\/p>\n<pre><code>$this-&gt;googleObj-&gt;setAccessToken($googleUsrToken);\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m having no luck calling the Google+ API for pushing a CommentActivity moment. I have been able to push an AddActivity successfully as well as a DiscoverActivity. I read somewhere on the internet whilst searching for a solution that the 400 HTTP Status represents that my user credentials are invalid, but I have been able [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3010","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3010","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3010"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3010\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}