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); 
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Please include your code – Linda Lawton - DaImTo Feb 09 '18 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("https://www.googleapis.com/plusPages/v2/people/$Id/activities", $options); $response = $request->getBody(); $googlePostResponse = $response->getContents(); $googlePostResponse = json_decode($googlePostResponse, TRUE); – sophia mohla Feb 09 '18 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+ – Linda Lawton - DaImTo Feb 09 '18 at 11:45

1 Answers1

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.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • 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? – sophia mohla Feb 09 '18 at 11:47
  • The user needs access to your gsuite account in order to be able to post on behalf of the domain. – Linda Lawton - DaImTo Feb 09 '18 at 11:47
  • I would check the access and access.type you are sending. – Linda Lawton - DaImTo Feb 09 '18 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? – sophia mohla Feb 09 '18 at 11:50
  • you probably need to give those users access. I would check their permissions. – Linda Lawton - DaImTo Feb 09 '18 at 12:01
  • I added scope before connect Google Plus user. ` $this->client->addScope('https://www.googleapis.com/auth/plus.me'); $this->client->addScope('https://www.googleapis.com/auth/plus.stream.write'); $this->client->addScope('https://www.googleapis.com/auth/plus.stream.read'); $this->client->addScope('https://www.googleapis.com/auth/plus.pages.manage'); $this->client->addScope('https://www.googleapis.com/auth/plus.media.readwrite'); ` – sophia mohla Feb 09 '18 at 12:04
  • Those are the permissions your application is using to access the api. They have nothing to do with the users permissions on the domain itself. Contact your gsuite admin see if they have any information about the users access to the domain account. – Linda Lawton - DaImTo Feb 09 '18 at 12:34
  • I use business page API. In my project domain API does not required. – sophia mohla Feb 12 '18 at 10:19
  • Users need permission to write to your business page. Make sure they have been granted permissions. – Linda Lawton - DaImTo Feb 12 '18 at 11:01
  • Yes, I have permission to get Authentication from user to get permission of posting behalf the user. As I mention before. I have issue for some user only not all. On connection I got all permission which I need to post on user profile. – sophia mohla Feb 13 '18 at 07:46
  • You still dont understand the problem. The user you are authenticating with is trying to post to your business page. They cant do that unless you grant them permission on your business page to write to it. Just because you authenticate a user doesn't mean they have permission to do something. – Linda Lawton - DaImTo Feb 13 '18 at 08:46
  • If you cant post on a users profile until they are part of your domain account. – Linda Lawton - DaImTo Feb 13 '18 at 08:53