1
votes

I want to share my status to google plus.

I followed the google api, but i am getting the unauthorized error. I am trying to fix it for more then 2 days, but i could't..

i read this answer, i download and test the api, still not working for me.

401 Unauthorized access when posting Google+ Moments with PHP Client

You can check here,

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

In this trunk file, still they are calling the Google_PlusMomentsService.php

i tried the following code, but still not works - https://developers.google.com/+/api/latest/moments/insert

here is the live link which i am testing: http://webscarlets.in/projects/babblesuite/gplus/index.php

this is code i am using to share the status

 $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>';

can anyone fix it please.

Thanks to all

1

1 Answers

3
votes

You need to authorize the user in the PHP client and request visible actions (e.g. AddActivity) before you can write app activities to a user's profile. Because you're using the older sample, you probably aren't setting requestvisibleactions either in the button or in your OAuth2 flow.

Try starting here: https://developers.google.com/+/quickstart/php

This is the latest PHP starter and has been verified to work. If you really, really, want to use the older code you've shared, please share the sign-in button markup, e.g.:

<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>

Because I'm guessing you're missing the line: data-requestvisibleactions...