{"id":3009,"date":"2014-03-13T11:19:59","date_gmt":"2014-03-13T11:19:59","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/13\/how-to-insert-moment-through-google-plus-api-collection-of-common-programming-errors\/"},"modified":"2014-03-13T11:19:59","modified_gmt":"2014-03-13T11:19:59","slug":"how-to-insert-moment-through-google-plus-api-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/13\/how-to-insert-moment-through-google-plus-api-collection-of-common-programming-errors\/","title":{"rendered":"How to insert moment through google plus api?-Collection of common programming errors"},"content":{"rendered":"<p>I am using google plus api with codeigniter, everything works good except when I try to insert moment, it shows an authentication error while I am able to get G+ information through <code>$this-&gt;plus-&gt;people-&gt;get('me')<\/code>.<\/p>\n<p>I have this in CodeIgniter Library Construct:<\/p>\n<pre><code>    $CI =&amp; get_instance();\n    $CI-&gt;config-&gt;load('googleplus');\n\n    require APPPATH .'libraries\/google-api-php-client\/src\/Google_Client.php';\n    require APPPATH .'libraries\/google-api-php-client\/src\/contrib\/Google_PlusService.php';\n    $cache_path = $CI-&gt;config-&gt;item('cache_path');\n    $GLOBALS['apiConfig']['ioFileCache_directory'] = ($cache_path == '') ? APPPATH .'cache\/' : $cache_path;\n\n    $this-&gt;client_id = $CI-&gt;config-&gt;item('client_id', 'googleplus');\n    $this-&gt;client_secret = $CI-&gt;config-&gt;item('client_secret', 'googleplus');\n    $this-&gt;redirect_uri = $CI-&gt;config-&gt;item('redirect_uri', 'googleplus');\n\n    $this-&gt;client = new Google_Client();\n    $this-&gt;client-&gt;setApplicationName($CI-&gt;config-&gt;item('application_name', 'googleplus'));\n    $this-&gt;client-&gt;setClientId($this-&gt;client_id);\n    $this-&gt;client-&gt;setClientSecret($this-&gt;client_secret);\n    $this-&gt;client-&gt;setRedirectUri($this-&gt;redirect_uri);\n    $this-&gt;client-&gt;setDeveloperKey($CI-&gt;config-&gt;item('api_key', 'googleplus'));\n    $this-&gt;client-&gt;setAccessType(\"offline\");\n    $this-&gt;client-&gt;setScopes(array('https:\/\/www.googleapis.com\/auth\/plus.me','https:\/\/www.googleapis.com\/auth\/plus.login'));\n    $this-&gt;client-&gt; setApprovalPrompt(\"force\");\n    $this-&gt;plus = new Google_PlusService($this-&gt;client); \n<\/code><\/pre>\n<p>And here is sample what I am doing to insert moment.<\/p>\n<pre><code>    $target = new Google_ItemScope();\n    $target-&gt;url = 'https:\/\/developers.google.com\/+\/plugins\/snippet\/examples\/thing';\n\n    $moment = new Google_Moment();\n    $moment-&gt;type = \"http:\/\/schemas.google.com\/AddActivity\";\n    $moment-&gt;target = $target;\n\n    $this-&gt;plus-&gt;moments-&gt;insert('me', 'vault', $moment);\n<\/code><\/pre>\n<p>I am getting this error when trying to insert moment.<\/p>\n<p>Fatal error: Uncaught exception &#8216;Google_ServiceException&#8217; with message &#8216;Error calling POST https:\/\/www.googleapis.com\/plus\/v1\/people\/me\/moments\/vault?key=<strong><em>*<\/em>**<em>*<\/em>**<\/strong>: (401) Unauthorized&#8217; in \/application\/libraries\/google-api-php-client\/src\/io\/Google_REST.php:66 Stack trace: #0 \/application\/libraries\/google-api-php-client\/src\/io\/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 \/application\/libraries\/google-api-php-client\/src\/service\/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 \/application\/libraries\/google-api-php-client\/src\/contrib\/Google_PlusService.php(167): Google_ServiceResource-&gt;__call(&#8216;insert&#8217;, Array) #3 \/application\/libraries\/googleplus.php(290): Google_MomentsServiceResource-&gt;insert( in \/application\/libraries\/google-api-php-client\/src\/io\/Google_REST.php on line 66<\/p>\n<p>I don&#8217;t know what I am doing wrong, please suggest me with code. Thanks \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am using google plus api with codeigniter, everything works good except when I try to insert moment, it shows an authentication error while I am able to get G+ information through $this-&gt;plus-&gt;people-&gt;get(&#8216;me&#8217;). I have this in CodeIgniter Library Construct: $CI =&amp; get_instance(); $CI-&gt;config-&gt;load(&#8216;googleplus&#8217;); require APPPATH .&#8217;libraries\/google-api-php-client\/src\/Google_Client.php&#8217;; require APPPATH .&#8217;libraries\/google-api-php-client\/src\/contrib\/Google_PlusService.php&#8217;; $cache_path = $CI-&gt;config-&gt;item(&#8216;cache_path&#8217;); $GLOBALS[&#8216;apiConfig&#8217;][&#8216;ioFileCache_directory&#8217;] = [&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-3009","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3009","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=3009"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3009\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}