0

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?

Patrick St.Onge
  • 173
  • 1
  • 10
  • >$client->setClientId('123.apps.googleusercontent.com'); wouldn;'t the clientId be an email address? – Dmitry Aug 03 '18 at 01:47

1 Answers1

0

user does not have sufficient permissions for this profile

Means just that the user you have authenticated the script with does not have permission to access the profile you are trying to access.

You have not included any of the code used to access Google analytics but you should have something like view id or profile id in there some where. You need to login with a user with access to it.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449