I've just updated to the latest version of the google-api-php-client
. Can't find the previous version number I was running, but it's from back when it was on code.google.com. Definitely a few years old.
Getting this error, under specific circumstances.
{"error":{"errors":[{"domain":"global","reason":"insufficientPermissions","message":"User does not have sufficient permissions for this profile."}],"code":403,"message":"User does not have sufficient permissions for this profile."}}
This code used to work fine with the old version. What I'm doing is looping through a few google analytics accounts to read some data. I have the following code before the loop.
$client = new Google_Client();
$client->setApplicationName("name");
$client->setClientId('123.apps.googleusercontent.com');
$client->setClientSecret('secret');
$service = new Google_Service_Analytics($client);
Then inside the loop, for each account, I do $client->refreshToken($token)
. $token
is the refresh token saved in the database. If I go through only one account, it works fine. The problem appears to be because I reuse the same Google_Client
object. If I redefine Google_Client
inside my loop, it works as intended. But that feels dirty, especially when the name, id, and secret are all the same. I should note that when I run $client->refreshToken($token)
the access token is set correctly, which I confirmed with $client->getAccessToken()
.
Is there a proper way to reset the Google_Client
object so I don't redefine it?