1
votes

I need your help:

I am using Google AdWords API PHP library and integrated it in Symfony2. I generate the URL to get the Refresh_token and it seems to work fine, I receive the refresh token. But everytime I want to access the API I get an "invalid_grant" error.

I checked my gMail-Test Account and couldn't find my App.

So that's what I do:

I generate the Access-URL, it's working fine:

https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=4160XXXXX-7j6qpXXXXXXXXXXXXkctXXX.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%2F%2Fadcheck%2Fweb%2Fapp_dev.php%2Fapp%2Ftoken%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords&access_type=offline&approval_prompt=force

I click on it and accept it, so that my "AdWords Web" App can access and manage my Google AdWords Account.

Google then redirects me to my Redirect_uri and is sending the refresh_token:

http://localhost/adcheck/web/app_dev.php/app/token/?code=4/ughxxxxxxxxxxxxxxxxxxxxxxxxxIZeF5yoMzI#

But the "AdWords Web" App isn't connected. I can't find it on my Google Account Apps list, although I get a successful answer and the refresh token.

Anyone can help? I'm helpless and can't find whats wrong :/

1

1 Answers

0
votes

Ok, I found it! Google doesn't return the refresh token with. Google returns an Access_token which then can be used to generate the refresh_token.

 $AdWordsUser->SetOAuth2Info(
        $OAuth2Handler->GetAccessToken(
            $AdWordsUser->GetOAuth2Info(), $code, $redirectUri));
$AdWordsUser->SetRefreshToken($AdWordsUser->GetOAuth2Info('refresh_token'));

with the Access_token generated by Google using the $redirectUri

$code = $this->get('request')get->('code');

When you first attempt to get the refresh_token by your access token, Google adds it to the "My Apps" site on your personal Google Account. :)