Post to Google Plus Wall(activities)
i tried everything, i searched a lot. but there is no good documentation about this. i tried using custom http request, i tried by using PlusDomains Service. but nothing work. can anyone give me a clear guide about this.
these are the ways i tried for now....
$client = new Google_Client();
// $client->useApplicationDefaultCredentials();
$scopes = [Google_Service_Plus::PLUS_ME, Google_Service_PlusDomains::PLUS_STREAM_WRITE];
$client->setAuthConfig(storage_path('app') . '/client_secrets.json');
$client->setAccessType("offline");
if($client->isAccessTokenExpired()) {
$client->refreshToken($google->refresh_token);
/*$authData = AuthData::find($google->id);
$authData->access_token = $client->getAccessToken()['access_token'];
$authData->access_secret = $client->getAccessToken()['id_token'];
$authData->refresh_token = $client->getRefreshToken();
$authData->save();*/ // this is something relevent to my laravel model works
$client->setAccessToken($client->getAccessToken()['access_token']);
}
$client->setAccessToken($google->access_token);
$http = $client->authorize();
$client->setScopes($scopes);
$plus = new Google_Service_Oauth2($client);
$userId = $plus->userinfo->get()->id;
$plusDomain = new Google_Service_PlusDomains($client);
$activity = new Google_Service_PlusDomains_Activity();
$obj = new Google_Service_PlusDomains_ActivityObject();
$obj->setContent("Test text");
$obj->setActor($userId);
$activity->setObject($obj);
$activity->setActor($userId);
$activity->setTitle("title");
return $plusDomain->activities->insert($userId, $activity);
// $url = sprintf('https://www.googleapis.com/plusDomains/v1/people/%s/activities', $userId);
//
// $headers = ['content-type' => 'application/json'];
//
//
// $httpRequest = new \GuzzleHttp\Psr7\Request('POST', $url, $headers, json_encode($body));
//
// // make the HTTP request
// $response = $http->send($httpRequest);
//
// return $response;
i tried again.. i can see the requests on Google API Console. but it shows client errros... this is what i get when i try to work...
Google_Service_Exception in REST.php line 118:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
Hello, I have the same problem as you. Also "Forbidden" status. Have you found any solution? Thank you in advance
@ir3nicus, we can't post through the normal gmail account.we have to use a gsuite account to get full acess for plusDomain features. i think that we have to access google api through that gsuite account email.
@ir3nicus It is most likely the userId you are using does not have access to the Plus Domains API.
Hello, ok thank you for replay. When I access Plus Domain API.( I launched new app from Google Suite Account). Then every Google user can access it or only users that has Google Suite Account too?
2017-05-01 18:44 GMT+02:00 Brent Shaffer [email protected]:
Closed #1195 https://github.com/google/google-api-php-client/issues/1195 .
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/google/google-api-php-client/issues/1195#event-1064178593, or mute the thread https://github.com/notifications/unsubscribe-auth/ADtoqEc_De9pcGOiWvggZsEJpuxM9oGSks5r1gv1gaJpZM4M3oqM .
--
Pozdrawiam Marcin Mazanek
It doesn't matter who creates the Google Console API app. What matters is that the user whose credentials are being used for the request is a paid G Suite user. Last I checked the posted content had to be private to that company as well.
@abraham so then how buffer, hootsuite type websites post the content to the G+. i wanted to do the same thing...
Google has a handful of partners that have elevated access.
@abraham can i/our company get that too?
As far as I know Google will reach out to any companies they are interested in adding to the program.
Just spent a good amount of time reading the G+ docs (likely not well enough) and getting all the OAuth dance, API Console Project stuff, etc, out of the way...only to find that all attempts to use any access_token granted to my app/credentials would be responded to with this same 403 Forbidden:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
If I'm understanding correctly what @abraham and @bshaffer have been saying it's that this will never work unless:
- I have a G Suite domain set up for my domain (let's say it's
example.com). - I have connected my App and my domain
example.comto one another. - The User who's gone through the OAuth process and granted my app permissions must be an
@example.comUser. OR - I am considered "special" by Google and elevated permissions are granted to my app allowing for free users with
@gmail.com, etc, domains to be accessed by my app.
Is that correct, and is it not enough to do steps 1. and 2. only? If so, I'm afraid this would render all my work on this useless since we'd want to allow arbitrary Users to grant our app access to do things on their behalf.
2 isn't needed. Assuming a G Suite organization is configured their users can us any app and post to their domain's Google+ via that app.
But basically yes. @gmail.com users can't generally post to Google+ through the API.
Hi, any idea on how to contact google to become 'special' under point 4 of @newhouse post?
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.???