An error has occurred: { "error" : "invalid_grant" }

5,553 views
Skip to first unread message

Jur

unread,
Aug 8, 2013, 12:15:48 PM8/8/13
to adwor...@googlegroups.com
Hello Guys,
 
I'm working on my first Google Adwords API application, but I can't get passed the oauth2 verification.
I could get a refresh_token with the GetRefreshToken.php script, but I get the error : An error has occurred: { "error" : "invalid_grant" } when I request a list of campaines in my test account.
 
Hope someone can help me out in the right direction.
 
Regards,
 
Jur
 
MMC id : 916-243-9387

Takeshi Hagikura (AdWords API Team)

unread,
Aug 19, 2013, 4:30:24 AM8/19/13
to adwor...@googlegroups.com
Hi Jur, 

What clientId and clientSecret are you passing to the script when you run the GetRefreshToken.php script?
And can you please share the request xml when you run the GetCampaign (except for the sensitive info)? 

Best,
- Takeshi, AdWords API Team
Message has been deleted

Takeshi Hagikura (AdWords API Team)

unread,
Aug 20, 2013, 11:37:50 AM8/20/13
to adwor...@googlegroups.com
Hi Jur,

Sorry I didn't mean to post client id and client secret. 
I wanted to know what account did use to get your client id and client secret.

If you used your MCC account under which your test account is in or the test account itself for getting client id and secret,
the CampaignService.get should work. 

Also I wanted to confirm the xml request log for CampaignService.get. 
Specifically clientCustomerId (for your test account) was included in the soap header. 

Best,
- Takeshi,

On Tuesday, August 20, 2013 8:54:23 PM UTC+9, Jur wrote:
Hello Takeshi,

Clientid: xxxxxxx
Client_secreat:xxxxxxx

I use the standard getCampainsExample function:

// Include the AdWordsUser
require_once LIB_PATH . '/AdWordsUser.php';

function GetCampaignsExample(AdWordsUser $user) {
  // Get the service, which loads the required classes.
  $campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);

  // Create selector.
  $selector = new Selector();
  $selector->fields = array('Id', 'Name');
  $selector->ordering[] = new OrderBy('Name', 'ASCENDING');

  // Create paging controls.
  $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

  do {
    // Make the get request.
    $page = $campaignService->get($selector);

    // Display results.
    if (isset($page->entries)) {
      foreach ($page->entries as $campaign) {
        printf("Campaign with name '%s' and ID '%s' was found.\n",
            $campaign->name, $campaign->id);
      }
    } else {
      print "No campaigns were found.\n";
    }

    // Advance the paging index.
    $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
  } while ($page->totalNumEntries > $selector->paging->startIndex);
}

try {
  // Get AdWordsUser from credentials in "../auth.ini"
  // relative to the AdWordsUser.php file's directory.
  $user = new AdWordsUser();
  // Log every SOAP XML request and response.
  $user->LogAll();
  
  // Run the example.
  GetCampaignsExample($user);
} catch (Exception $e) {
print_r($e);
  printf("An error has occurred: %s\n", $e->getMessage());
}


Op maandag 19 augustus 2013 10:30:24 UTC+2 schreef Takeshi Hagikura (AdWords API Team):

Jur

unread,
Aug 21, 2013, 7:53:06 AM8/21/13
to adwor...@googlegroups.com
Hello Takeshi,

I did find it a strange request, but I did send it anyway :-)
Thanks for removing the message.

I think this is the XML send :

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201306"><SOAP-ENV:Header><ns1:RequestHeader><ns1:clientCustomerId>823-418-1279</ns1:clientCustomerId><ns1:developerToken>xxxx</ns1:developerToken><ns1:userAgent>RIS_Online_Conversion (AwApi-PHP/4.4.0, Common-PHP/5.0.0, PHP/5.3.3)</ns1:userAgent></ns1:RequestHeader></SOAP-ENV:Header><SOAP-ENV:Body><ns1:get><ns1:serviceSelector><ns1:fields>Id</ns1:fields><ns1:fields>Name</ns1:fields><ns1:ordering><ns1:field>Name</ns1:field><ns1:sortOrder>ASCENDING</ns1:sortOrder></ns1:ordering><ns1:paging><ns1:startIndex>0</ns1:startIndex><ns1:numberResults>500</ns1:numberResults></ns1:paging></ns1:serviceSelector></ns1:get></SOAP-ENV:Body></SOAP-ENV:Envelope>

Op dinsdag 20 augustus 2013 17:37:50 UTC+2 schreef Takeshi Hagikura (AdWords API Team):

Jur

unread,
Aug 21, 2013, 10:05:34 AM8/21/13
to adwor...@googlegroups.com
Hello Takeshi,

I think the error is in this part of the code in the file /Common/Lib/AdsSoapClient.php:
$response = parent::__soapCall($function_name, $arguments, $options,
          $input_headers, $output_headers);

Hope you can help me!

Regards,

Jur

Op woensdag 21 augustus 2013 13:53:06 UTC+2 schreef Jur:

Takeshi Hagikura (AdWords API Team)

unread,
Aug 22, 2013, 1:39:26 AM8/22/13
to adwor...@googlegroups.com
Hi Jur,

The SOAP xml looks right to me. 

So next, what account did you use in api console to retrieve your client id and client secret?
Also did you replace the refresh_token in your auth.ini by the refresh token returned in GetRefreshToken.php?

Best,
- Takeshi, 

Jur

unread,
Aug 22, 2013, 3:44:54 AM8/22/13
to adwor...@googlegroups.com
Hello Takeshi,

I used my MCC account to generate the client_id and client_secret.

 Client ID for installed applications

Client ID:xxx
Client secret:
xxx
Redirect URIs: urn:ietf:wg:oauth:2.0:oob http://localhost

The GetRefreshToken.php didn't give me a refresh token immediately it gave me this :


After I go to the link a get a page with:
This app would like to:
Manage your AdWords campaigns
Adsys and Google will use this information in accordance with their respective terms of service and privacy policies.

I click accept and get :
Please copy this code, switch to your application and paste it there:

With the token there.

I put that token in auth,ini

Regards,

Jur


Op donderdag 22 augustus 2013 07:39:26 UTC+2 schreef Takeshi Hagikura (AdWords API Team):

Robert Rafai

unread,
Aug 22, 2013, 4:32:29 PM8/22/13
to adwor...@googlegroups.com
Look at my Posting:
https://groups.google.com/forum/?hl=en#!topic/adwords-api/ka19cZNbQo8

Its not the Refresh_token, it is the Authcode.
I have inserted in the getrefreshtoken.php and then i got the refresh_token.

Takeshi Hagikura (AdWords API Team)

unread,
Aug 23, 2013, 1:05:23 AM8/23/13
to adwor...@googlegroups.com
Hi Jur,

I got it. 

> I click accept and get :
> Please copy this code, switch to your application and paste it there:
In that step, when you get is an authorization code (kind of one time password) that can be used to generate access token (and refresh token when offline-mode).
In GetRefreshToken.php, the line 65 does that. 
Then, refresh token should be returned.

In the auth.ini, please use that refresh token, not the authorization code. 

Hope this helps. 
Best,
- Takeshi, 

Jur

unread,
Aug 23, 2013, 2:03:10 PM8/23/13
to adwor...@googlegroups.com
Hello Takeshi,

Problem solved!!!!

Thanks, I feel a bit stupid I didn't think of this.
But still, it's not that obvious.

Thanks again!

Regards,

Jur


Op vrijdag 23 augustus 2013 07:05:23 UTC+2 schreef Takeshi Hagikura (AdWords API Team):

Takeshi Hagikura (AdWords API Team)

unread,
Aug 26, 2013, 6:05:37 AM8/26/13
to adwor...@googlegroups.com
Hi Jur, 

Grad to hear that the problem resolved. 

Thanks,
- Takeshi, 

fan...@163.com

unread,
Jul 5, 2014, 12:36:07 AM7/5/14
to adwor...@googlegroups.com
Hi Takeshi, Get refresh toke URL is not this https://accounts.google.com/o/oauth2/*****. thanks.

Takeshi Hagikura (AdWords API Team)於 2013年8月23日星期五UTC+8下午1時05分23秒寫道:

Regards,

Jur

youfindad...@gmail.com

unread,
Jul 6, 2014, 10:16:32 PM7/6/14
to adwor...@googlegroups.com
Hi Takeshi,

         How to get refresh token,Is not this address to obtain:https://accounts.google.com/o/oauth2/auth?scope=email%20profile&redirect_uri=http://localhost&response_type=code&client_id=


Hope you can help me!

Regards,

abel


Takeshi Hagikura (AdWords API Team)於 2013年8月23日星期五UTC+8下午1時05分23秒寫道:
Hi Jur,

youfindad...@gmail.com

unread,
Jul 6, 2014, 10:19:56 PM7/6/14
to adwor...@googlegroups.com
Hi Takeshi,

How to get refresh token.

Is not this address to obtain:


Hope you can help me!
Regards,
abel

Takeshi Hagikura (AdWords API Team)於 2013年8月23日星期五UTC+8下午1時05分23秒寫道:
Hi Jur,

youfindad...@gmail.com

unread,
Jul 6, 2014, 10:29:15 PM7/6/14
to adwor...@googlegroups.com


Hope you can help me!

Regards,

Abel


Takeshi Hagikura (AdWords API Team)於 2013年8月23日星期五UTC+8下午1時05分23秒寫道:
Hi Jur,

Michael Cloonan (AdWords API Team)

unread,
Jul 9, 2014, 1:42:48 PM7/9/14
to adwor...@googlegroups.com
Hello Abel,

You can find a guide that includes utilities that will help generate the refresh token for you on our AdWords-specific OAuth 2.0 guide.

Alternatively, if you would like to generate your own refresh token, you can look at our more generic guide, although this manual process is considerably more difficult.

Regards,
Mike, AdWords API Team
Reply all
Reply to author
Forward
0 new messages