google-api-php-client icon indicating copy to clipboard operation
google-api-php-client copied to clipboard

new post to google plus

Open alibehroozi opened this issue 9 years ago • 7 comments

I want to use php to post to google plus. But google plus return "403 forbidden" I want you to give me a piece of code to make it possible.

This is my auth function : global $client; $client->setAuthConfig("/home/----"); $client->setRedirectUri("----");

$client->addScope("https://www.googleapis.com/auth/plus.stream.write"); $client->addScope("https://www.googleapis.com/auth/plus.me"); $authUrl = $client->createAuthUrl(); header("Location: $authUrl"); die;

And this is my new post function : $client->setAccessToken($token); $plus = new Google_Service_Plus($client); $plusdomains = new Google_Service_PlusDomains($client); $postBody = new Google_Service_PlusDomains_Activity(); $postBody['object']['originalContent'] = 'Happy Monday!'; $result = $plusdomains->activities->insert('me', $postBody);

$result = $plus->people->get('me');

$response->getBody()->write(var_export($result, true));

but the result is : { "error": { "errors": [ { "domain": "global", "reason": "forbidden", "message": "Forbidden" } ], "code": 403, "message": "Forbidden" } }

As you know ,many sites are now available that send new posts using google oauth to all kind of google plus account ( not only google apps ) ( for example : buffer.com)

Please help me

alibehroozi avatar Jan 12 '17 14:01 alibehroozi

Hello. You are making two calls to the API and writing both to $result, which is confusing. Do any calls to the API return as expected? If not, then I'd guess your access token is invalid.

Can you verify that the $token being passed to the client is a valid access token?

bshaffer avatar Jan 12 '17 18:01 bshaffer

Try the google plus example shown here and see if you have any luck

bshaffer avatar Jan 12 '17 19:01 bshaffer

Thanks for your attention token is valid because I return that in every request But every thing I do , I will see "Forbidden 403". Would you please give me a piece of code that post to google plus page ? The bad thing is I try the google api explorer And I get 403 Forbidden too. If you give me a code that works , You resolve my problem.

alibehroozi avatar Jan 13 '17 09:01 alibehroozi

Closing this issue due to inactivity. Please let me know if you were able to get this working.

bshaffer avatar Mar 14 '17 16:03 bshaffer

Nope

alibehroozi avatar Mar 15 '17 12:03 alibehroozi

Which email address are you using? If the email address of the that you are using ends with gmail.com, then it won't work. The Domains API only works with apps.google.com accounts that use custom domains.

sunil-lulla avatar Apr 06 '17 14:04 sunil-lulla

I need an account in apps.google.com, soo i m going to buy to post in google plus. Which plan i need to buy.???

BilalBasha avatar Feb 07 '18 12:02 BilalBasha