My Business
1.9K members online now
1.9K members online now
For developers who are using the Google My Business API to manage locations
Guide Me
star_border
Reply

POST https://www.googleapis.com/oauth2/v4/token` resulted in a `500 Internal Server Error`

[ Edited ]
Follower ✭ ☆ ☆
# 1
Follower ✭ ☆ ☆

Server error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `500 Internal Server Error` response: { "error": "internal_failure", "error_description": "Backend Error" }

 

Every in a while we see this error when doing multiple locations updates through the GoogleMyBusiness Api,   I am using a php reset function for the auth

 

public function refreshToken()
{
if ($this->googleClient->isAccessTokenExpired()) {
$result = $this->googleClient->refreshTokenWithAssertion();
if (!isset($result['access_token'])) {
throw new \Exception('unexpected response: ' . json_encode($result));
}
$this->oauth2Token = $result['access_token'];
}
return $this->oauth2Token;
}

Perhaps there is a better way?
1 Expert replyverified_user

Re: POST https://www.googleapis.com/oauth2/v4/token` resulted in a `500 Internal Server Error`

Google Employee
# 2
Google Employee

Hi @Jeremy M,

 

Please make sure that you are using the v1-branch of the repository on GitHub for the Google API Client Library for PHP according to the README.txt file in the PHP client library package.

 

Judging from the source code you provided, you are running a service account application, and the syntax of your code is incorrect for your application to resend the token request to the Google OAuth 2.0 Authorization Server, which returns an access token.

 

Please follow the code snippet below for using a service account with v1-branch of the Google API Client Library for PHP:

include_once "Mybusiness.php";

 

$client_email = '1234567890-a1b2c3d4e5f6g7h8i@developer.gserviceaccount.com'; //Service Account Email Address

$private_key = file_get_contents('MyProject.p12'); //key.p12

$scopes = array('https://www.googleapis.com/auth/plus.business.manage');

 

$client = new Google_Client();

$client->setApplicationName("Google My Business API Examples");

 

if (isset($_SESSION['service_token'])) {

 $client->setAccessToken($_SESSION['service_token']);

}

 

// Email address of the user account to impersonate

$user_to_impersonate = 'user@example.org';

$credentials = new Google_Auth_AssertionCredentials(

   $client_email,

   $scopes,

   $private_key,

   'notasecret',                                 // Default P12 password

   'http://oauth.net/grant_type/jwt/1.0/bearer', // Default grant type

   $user_to_impersonate

);

$client->setAssertionCredentials($credentials);

 

if ($client->getAuth()->isAccessTokenExpired()) {

 $client->getAuth()->refreshTokenWithAssertion($credentials);

}

$_SESSION['service_token'] = $client->getAccessToken();

 

/************************************************

 We are going to create the Google My Business API

 service, and query it.

************************************************/

$mybusinessService = new Google_Service_Mybusiness($client);

 

Thanks,

Terry