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)
Google Plus domains is not Google+ the social media website. This is two separate APIs.
Answer: You are getting an error because you don't appear to have a Google plus domains account. or the user you are authenticating with does not have access to a Google plus domain. If you are trying to write to a domain then makes sure that you have the correct user.
Google+ the social media website:
The google+ api is a read only API and does not allow you to programmatically post to the google+ social media website.
Correction: buffer lets you post to a google plus page / domain account not to the google+ social media website. I do know now of any application that can post to google+ the social media website besides googles own. Buffer users domains api allowing Google at work customers, possibly google classroom and google aps to post to the walls of their sites. This does not post to a normal user account on the Google+ social media website.
There is also the Google pages api which is beta requires special access and probably only for major companies.