Error refreshing the OAuth2 token, message: '{ "error" : "unauthorized_client", "error_description" : "Unauthorized client or scope in request." }'
19,695
You are missing the final step which is giving access to your application in the control panel of your domain.
https://developers.google.com/+/domains/authentication/delegation
You created the service account, now you need to delegate/authorize the application.
Author by
andynador
Updated on June 16, 2022Comments
-
andynador almost 2 years
When I try to fetch data from Google Analytics, I got error
Error refreshing the OAuth2 token, message: '{ "error" : "unauthorized_client", "error_description" : "Unauthorized client or scope in request." }'
I create project in my https://console.developers.google.com/project, create Service account and download .p12 key. Also enable "Analytics API" in project settings, but it doesn't work. This is my code:
$service_account_name = '<Service Email>@developer.gserviceaccount.com'; $key_file_location = '<keyName>.p12'; $key = file_get_contents($key_file_location); $cred = new Google_Auth_AssertionCredentials( $service_account_name, array(Google_Service_Analytics::ANALYTICS), $key, 'notasecret', 'http://oauth.net/grant_type/jwt/1.0/bearer', '<My email>' ); $client->getAuth()->setAssertionCredentials($cred); $service = new Google_Service_Analytics($client); $result = $service->data_ga->get("ga:<profileID>", "yesterday", "today", "ga:pageviews"); print_r( $result);
What is wrong with my project? Please help.
-
miturbe almost 9 yearsDid you add the project to your domain? add the clientId and scopes?
-
andynador over 8 yearsNo, I ididn't. Could you tell me, where I need add this parametres?
-
andynador over 8 yearsHas anyone ideas, what's wrong with my project?
-
-
Uday Posia about 3 yearsCan you please explain more? I am trying to use Gmail for WP SMTP plugin in WordPress website to send emails. But after following each steps it shows errro
-
Uday Posia about 3 yearsMailer: Gmail { "error": "unauthorized_client", "error_description": "Unauthorized" }