0

I got issue to post on users profile (Not got error on all users).

Error Code: 400 Error Message: Calls to this method must be made by or on behalf of a Google+ Page.

$options = array( "headers" => array( 'content-type' => 'application/json;' ), "body" => json_encode($activity) );
$httpClient = $this->gplus->client->authorize(); 
$request = $httpClient->post("googleapis.com/plusPages/v2/people/$Id/activities";, $options);
$response = $request->getBody();
$googlePostResponse = $response->getContents();
$googlePostResponse = json_decode($googlePostResponse, TRUE); 
3
  • Please include your code Commented Feb 9, 2018 at 11:34
  • @DaImTo code $options = array( "headers" => array( 'content-type' => 'application/json;' ), "body" => json_encode($activity) ); $httpClient = $this->gplus->client->authorize(); $request = $httpClient->post("googleapis.com/plusPages/v2/people/$Id/activities", $options); $response = $request->getBody(); $googlePostResponse = $response->getContents(); $googlePostResponse = json_decode($googlePostResponse, TRUE); Commented Feb 9, 2018 at 11:41
  • You might want to edit your topic and tags. That is domains api not google puls this has nothing to do with Google+ Commented Feb 9, 2018 at 11:45

1 Answer 1

0

The code you are currently using is to the Google Domains api. The error means that the user you have currently authenticated with doesnt have access to the domains account. Make sure to grant the user access and they will be able to post to the Domains google+ page authentication

Note:

There is a difference between the Google+ API (Socialmedia website) and the Google Domains API (Gsuite)

The google+ api is read only and does not allow for programiticly inserting posts into Google+.

How authentication works

When you authenticate your application using these scopes

$this->client->addScope('googleapis.com/auth/plus.me'); 
$this->client->addScope('googleapis.com/auth/plus.stream.write'); 
$this->client->addScope('googleapis.com/auth/plus.stream.read'); 
$this->client->addScope('googleapis.com/auth/plus.pages.manage'); 
$this->client->addScope('googleapis.com/auth/plus.media.readwrite');

You are asking the user can I do these things on your behalf. However if the user does not have permission to do something your not going to be able to do it.

calls to this method must be made by or on behalf of a Google+ Page.

The user you are authenticating with does not have access to a business page. So your application cant write to a business page. You can only post to a domain account if you have a gsuite account. If you don't have one then you cant post to it. you cant just give them the id of your business page because again they dont have access to write to your business page.

12
  • Yes, But, I got this issue in some user cases. In other user's profile post working well with is code. is it wrong code then why worked in other user's profile post? Commented Feb 9, 2018 at 11:47
  • The user needs access to your gsuite account in order to be able to post on behalf of the domain. Commented Feb 9, 2018 at 11:47
  • I would check the access and access.type you are sending. Commented Feb 9, 2018 at 11:50
  • This code successfully working on around 1400 user's profile posting. Got this error in around 26 user only. Need to change code? Commented Feb 9, 2018 at 11:50
  • you probably need to give those users access. I would check their permissions. Commented Feb 9, 2018 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.