how to fix OAuth "Invalid_grant" error.

8,382 views
Skip to first unread message

ankitt...@gmail.com

unread,
Sep 12, 2020, 3:47:20 AM9/12/20
to AdWords API and Google Ads API Forum
Please help me how to fix this.

Google Ads API Forum Advisor Prod

unread,
Sep 14, 2020, 7:08:49 PM9/14/20
to ankitt...@gmail.com, adwor...@googlegroups.com
Hi Ankit,

Thank you for reaching out. The "invalid_grant" error usually indicates that the access or refresh token being passed in your request is incorrect or invalid. Please make sure the email address used to generate the OAuth credentials has access to your account. If it does, please try generating a new set of OAuth credentials by following the guide here.

If you are still having an issue, please share the email address you are using to generate the credentials as well as your client customer ID.

Thanks,
Google Logo
Nirmitabahen Gaurav Patel
Google Ads API Team
 


ref:_00D1U1174p._5004Q24apbu:ref

ankitt...@gmail.com

unread,
Sep 24, 2020, 8:47:33 AM9/24/20
to AdWords API and Google Ads API Forum
Hello  Nirmitabahen Gaurav Patel,

I want to link MCC account with another MCC account. using API php

But I could get the MCC ID in oauth2 when allow the service. and I can only get the Id for customer adwords account. not for MCC account.

Actually , I want to get the MCC Adwords ID using oauth2. when allow the service.

Thanks 

Google Ads API Forum Advisor Prod

unread,
Sep 24, 2020, 7:14:55 PM9/24/20
to ankitt...@gmail.com, adwor...@googlegroups.com
Hi Ankitt,

Thanks for reaching out. With regards to your concern, can you please provide complete request and response logs along with customer id so that i can further investigate the issue. Please reply privately author option while sharing details.

ankitt...@gmail.com

unread,
Sep 25, 2020, 4:43:09 AM9/25/20
to AdWords API and Google Ads API Forum
Hello  Nirmitabahen Gaurav Patel,

-> When I try to get MCC adwords account id by oauth2 then I am getting CUSTOMER_NOT_FOUND exception. 

-> I have two MCC adwords account.
1) 873-196-8266  (OUR MCC ACCOUNT)
2) 975-404-7233 (CLIENT MCC ACCOUNT)

-> I want to link "CLIENT MCC ACCOUNT" with "OUR MCC account". but I want to get CLIENT MCC account ID by oauth2 API php.

Thanks

Google Ads API Forum Advisor Prod

unread,
Sep 25, 2020, 7:23:54 PM9/25/20
to ankitt...@gmail.com, adwor...@googlegroups.com
Hi Ankitt,

The AuthenticationError.CUSTOMER_NOT_FOUND error is encountered when no Google Ads account is found for the customer Id provided in the header. Could you please confirm if the client customer Id(CID) belongs to a valid account and if the OAuth2 credentials were created using an email address which has access to your account(s). If the issue still persists, could you please share the complete request and error response logs for me to investigate further?

ankitt...@gmail.com

unread,
Sep 26, 2020, 10:45:49 AM9/26/20
to AdWords API and Google Ads API Forum
Thanks for give me the solutions. I did investigate this. But I am getting same error.

Google have 3 types of adwords account.
1) MCC account
2) Manager account
3) Client account.

I am right?

When I try to allow the oauth2 service with Manager account then I got success.
When I try to allow the oauth2 service with Client account then I got success.
When I try to allow the oauth2 service with MCC account then I got error. "CUSTOMER_NOT_FOUND"

I means, I want to get MCC account ID and LINK WITH OUR MCC ACCOUNT.

$oauth2 = new OAuth2([
'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',
'redirectUri' => 'http://exaplne.com/index.php',
'clientId' => '******************************************.apps.googleusercontent.com',
'clientSecret' => '*****************',
'access_type' => 'offline',
'prompt' => 'consent',
]);
if (!isset($_GET['code'])) {

$oauth2->setState(sha1(openssl_random_pseudo_bytes(1024)));
$_SESSION['oauth2state'] = $oauth2->getState();

$config = [
'access_type' => 'offline'
];
header('Location: ' . $oauth2->buildFullAuthorizationUri($config));
exit;
} else {
$oauth2->setCode($_GET['code']);
$authToken = $oauth2->fetchAuthToken();
$refresh_token = $authToken['access_token'];
}

$session = (new AdWordsSessionBuilder())->fromFile('getcustomerid.ini')->withOAuth2Credential($oauth2)->build();

/* Creating object of Adwords services */
$adWordsServices = new AdWordsServices();

/* Adwords Customer services */
$customerService = $adWordsServices->get($session, CustomerService::class);
$customers = $customerService->getCustomers();
$customerId = $customers[0]->getCustomerId();

ankitt...@gmail.com

unread,
Sep 26, 2020, 10:55:16 AM9/26/20
to AdWords API and Google Ads API Forum
Fatal error: Uncaught Google\AdsApi\AdWords\v201809\cm\ApiException: [AuthenticationError.CUSTOMER_NOT_FOUND @ ] in D:\xampp\htdocs\ppcfraud\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\Util\Reflection.php:43 Stack trace: #0 D:\xampp\htdocs\ppcfraud\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\Util\Reflection.php(43): ReflectionClass->newInstanceArgs(Array) #1 D:\xampp\htdocs\ppcfraud\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\AdsSoapClient.php(202): Google\AdsApi\Common\Util\Reflection->createInstance('Google\\AdsApi\\A...', Array) #2 D:\xampp\htdocs\ppcfraud\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\AdsSoapClient.php(164): Google\AdsApi\Common\AdsSoapClient->parseApiExceptionFromSoapFault(Object(SoapFault)) #3 D:\xampp\htdocs\ppcfraud\vendor\googleads\googleads-php-lib\src\Google\AdsApi\AdWords\v201809\mcm\CustomerService.php(95): Google\AdsApi\Common\AdsSoapClient->__soapCall('getCustomers', Array) #4 D:\xampp\htdocs\ppcfraud\mccacounttest\index.php(53): Google\AdsApi\AdWords\v201809\mcm\CustomerService->getCustomers() #5 {main} thrown in D:\xampp\htdocs\ppcfraud\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\Util\Reflection.php on line 43  

Google Ads API Forum Advisor Prod

unread,
Sep 28, 2020, 12:54:04 PM9/28/20
to ankitt...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for providing information. Can you please provide MCC account so that i can further investigate the issue.


Please reply privately author option while sharing details.

ankitt...@gmail.com

unread,
Sep 29, 2020, 6:09:08 AM9/29/20
to AdWords API and Google Ads API Forum

This is my MCC account.
Adwords ID: 873-196-8266  (OUR MCC ACCOUNT)

Please help me to fix the issue.

Thanks

Google Ads API Forum Advisor Prod

unread,
Sep 29, 2020, 6:49:36 PM9/29/20
to ankitt...@gmail.com, adwor...@googlegroups.com
Hi Ankitt,

Thanks for reaching out. With regards to your concern, I took a look at your account and you account access level is a "Test account". You can login in your account then go to Tools & Settings -> SETUP ->API Center and click "apply for basic access".

If you already submitted an application form and did not hear a response from them, you could raise your concerns to the Compliance Team by filling out this form

Please let me know if you have more questions.

Thanks,

Reply all
Reply to author
Forward
0 new messages