AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

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

using google/apiclient": "2.0.0-RC7" refreshTokenWithAssertion fails aroung 900 records in

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

I am running a script to patch 2000 business using Google My Business
At record 900 i get
"code": 401,
"message": "Request had invalid authentication credentials.",

Before each curl call I am checking the token

if ($client->isAccessTokenExpired()) {
$oauth2Token = $client->refreshTokenWithAssertion()['access_token'];
}

Are there any timeout issues here? Is this the correct implementation for "google/apiclient": "2.0.0-RC7"

2 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Jeremy M
May 2016

Re: using google/apiclient": "2.0.0-RC7" refreshTokenWithAssertion fails aroung 900 r

[ Edited ]
Google Employee
# 4
Google Employee

Hi @Jeremy M,

 

We suggest you use the v1-branch of the repository on GitHub as instructed on the Installation page of the API Client Library for PHP (Beta). Keep in mind that the API Client Library for PHP is separate from our PHP client library, which may not be compatible with the v2.0.0-RC7 release of the API Client Library for PHP.

 

Judging from the source code you provided, you tried to refresh the token using a service account's credentials but implemented the process incorrectly.

 

The following is a code snippet for using a service account with v1-branch of the API Client Library for PHP:

$service_account_name = '1234567890-a1b2c3d4e5f6g7h8i@developer.gserviceaccount.com'; //Email Address

$key_file_location = 'MyProject.p12'; //key.p12

$key = file_get_contents($key_file_location);

$user_to_impersonate = 'user@example.org';

$cred = new Google_Auth_AssertionCredentials(

   $service_account_name,

   array('https://www.googleapis.com/auth/plus.business.manage'),

   $key,

   'notasecret',                                 // Default P12 password

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

   $user_to_impersonate

);

$client->setAssertionCredentials($cred);

 

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

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

}

 

In addition, it’s best practice to always use a fieldMask for specific fields of each location when performing update operations for a large account and please try to limit the API update calls usage of your project to 5 Queries Per Second (QPS).

 

Thanks,

Terry

View solution in original post

Re: using google/apiclient": "2.0.0-RC7" refreshTokenWithAssertion fails aroung 900 r

Top Contributor
# 2
Top Contributor

Hi @Jeremy M

 

I think the best people to talk to would be business support for this.

 

https://support.google.com/business/contactflow

 

Verification >> bulk verification



Tim Capper, Google My Business Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.

Find me on: Google+ | Twitter | Facebook | Linkedin
Tim operates a bespoke Local SEO Consultancy in the UK, Online Ownership

Re: using google/apiclient": "2.0.0-RC7" refreshTokenWithAssertion fails aroung 900 r

Follower ✭ ✭ ☆
# 3
Follower ✭ ✭ ☆
This is a coding issue. Not a support issue. The forum use to answer these directly.

Is that no longer an option?

Sent from my iPhone
Marked as Best Answer.
Solution
Accepted by topic author Jeremy M
May 2016

Re: using google/apiclient": "2.0.0-RC7" refreshTokenWithAssertion fails aroung 900 r

[ Edited ]
Google Employee
# 4
Google Employee

Hi @Jeremy M,

 

We suggest you use the v1-branch of the repository on GitHub as instructed on the Installation page of the API Client Library for PHP (Beta). Keep in mind that the API Client Library for PHP is separate from our PHP client library, which may not be compatible with the v2.0.0-RC7 release of the API Client Library for PHP.

 

Judging from the source code you provided, you tried to refresh the token using a service account's credentials but implemented the process incorrectly.

 

The following is a code snippet for using a service account with v1-branch of the API Client Library for PHP:

$service_account_name = '1234567890-a1b2c3d4e5f6g7h8i@developer.gserviceaccount.com'; //Email Address

$key_file_location = 'MyProject.p12'; //key.p12

$key = file_get_contents($key_file_location);

$user_to_impersonate = 'user@example.org';

$cred = new Google_Auth_AssertionCredentials(

   $service_account_name,

   array('https://www.googleapis.com/auth/plus.business.manage'),

   $key,

   'notasecret',                                 // Default P12 password

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

   $user_to_impersonate

);

$client->setAssertionCredentials($cred);

 

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

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

}

 

In addition, it’s best practice to always use a fieldMask for specific fields of each location when performing update operations for a large account and please try to limit the API update calls usage of your project to 5 Queries Per Second (QPS).

 

Thanks,

Terry

Re: using google/apiclient": "2.0.0-RC7" refreshTokenWithAssertion fails aroung 900 r

[ Edited ]
Top Contributor
# 5
Top Contributor

Brilliant Thanks @Terry W

 

You are now my go to guy for coding issues : )



Tim Capper, Google My Business Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.

Find me on: Google+ | Twitter | Facebook | Linkedin
Tim operates a bespoke Local SEO Consultancy in the UK, Online Ownership

Re: using google/apiclient": "2.0.0-RC7" refreshTokenWithAssertion fails aroung 900 r

Google Employee
# 6
Google Employee

Thanks @Tim Capper for offering help! Cheers!