Hi Alex, It seems that you're using the response code as the refresh token. You should exchange the code for a refresh_token and an access_token. The refresh_token you keep, the access_token you use for up to 1 hour.
Regards, - Paul, AdWords API Team. On Monday, 26 August 2013 16:18:02 UTC+2, alexande...@adticket.de wrote: > > Hello Paul, > > I've run the GetRefreshToken example and added the refresh_token in the > auth.ini but if I execute my script I always get the invalid_grand error. > But it works when I try to access adwords with curl on the command-line > and using the same refresh_token. I don't get it. > > Here my code: > > $clientId = 'xxxxxxxx.apps.googleusercontent.com'; > $clientSecret = xxxxxxxxxxxx'; > > try > { > if (isset($_REQUEST['code'])) > { > $user = Yii::app()->session['user']; > > $oauth2Info = array( > 'client_id' => $clientId, > 'client_secret' => $clientSecret, > 'refresh_token' => $_REQUEST['code'], > 'grant_type' => 'authorization_code', > 'redirect_uri' => 'https://localhost/Elaine/site/auth' > ); > > $user->SetOAuth2Info($oauth2Info); > > // on that call i get the invalid_grand error > $campaignService = $user->GetService('CampaignService', 'v201306'); > $selector = new Selector(); > $selector->fields = array('Id'); > $selector->paging = new Paging(0, 0); > $page = $campaignService->get($selector); > die; > } > > $redirectUri = 'https://localhost/Elaine/site/auth'; > $offline = false; > $user = new AdWordsUser(); > > $OAuth2Handler = $user->GetOAuth2Handler(); > $authorizationUrl = > $OAuth2Handler->GetAuthorizationUrl($user->GetOAuth2Info(), $redirectUri, > $offline); > > // Store the AdWordsUser in session. > Yii::app()->session['user'] = $user; > > // Redirect to authorization URL. > header('Location: ' . $authorizationUrl); > } > > And thats how my user-object looks like befor using GetService-Method. > AdWordsUser#1 > ( > [AdWordsUser:libVersion] => '4.4.0' > [AdWordsUser:libName] => 'AwApi-PHP' > [AdWordsUser:defaultVersion] => 'v201306' > [AdWordsUser:defaultServer] => 'https://adwords.google.com' > [AdWordsUser:email] => null > [AdWordsUser:password] => null > [AdWordsUser:userAgent] => 'xxxxx' > [AdsUser:requestHeaderElements] => array > ( > 'authToken' => null > 'userAgent' => 'xxxx > (AwApi-PHP/4.4.0, Common-PHP/5.0.0, PHP/5.4.9-4ubuntu2.2)' > 'clientCustomerId' => null > 'developerToken' => 'xxxxxxxxxxxxxxxx' > 'applicationToken' => null > ) > [AdsUser:logsDirectory] => '/var/www/Elaine' > [AdsUser:soapCompression] => true > [AdsUser:soapCompressionLevel] => '1' > [AdsUser:wsdlCache] => 0 > [AdsUser:authServer] => 'https://accounts.google.com' > [AdsUser:oauth2Info] => array > ( > 'client_id' => 'xxxxxxxxx.googleusercontent.com' > 'client_secret' => 'xxxxxxxxxxxxxx' > 'refresh_token' => 'xxxxxxxxxxxxxxxxxxxxxxxx' > 'grant_type' => 'authorization_code' > 'redirect_uri' => 'https://localhost/Elaine/site/auth' > ) > [AdsUser:oauth2Handler] => SimpleOAuth2Handler#2 > ( > [SimpleOAuth2Handler:curlUtils] => CurlUtils#3 > ( > ) > [OAuth2Handler:server] => 'https://accounts.google.com' > [*:scope] => 'https://adwords.google.com/api/adwords/' > ) > [AdsUser:libVersion] => '5.0.0' > [AdsUser:libName] => 'Common-PHP' > [AdsUser:defaultServer] => 'https://adwords.google.com' > [AdsUser:defaultVersion] => 'v201306' > ) > > Any idea what I'am doing wrong. > > Regards, > > Alex > > > > > Am Sonntag, 18. August 2013 18:00:12 UTC+2 schrieb Jur: >> >> Hello Paul, >> >> Thanks for your reply. >> >> I've run the GetRefreshToken.php and got an URL back with the text that I >> should open it in the browser. >> On that URL I got a token, so that script works perfectly. >> >> Any other idea? >> >> Regards, >> >> Jur >> >> Op donderdag 15 augustus 2013 17:33:24 UTC+2 schreef Paul Matthews >> (AdWords API Team): >>> >>> Can you confirm that you've both followed the instructions in the OAuth2 >>> Wiki page <https://code.google.com/p/google-api-adwords-php/wiki/OAuth2> >>> ? >>> >>> Specifically the part about running the GetRefreshToken.php >>> example<https://code.google.com/p/google-api-adwords-php/source/browse/examples/AdWords/Auth/GetRefreshToken.php>and >>> added the refresh_token to your >>> auth.ini<https://code.google.com/p/google-api-adwords-php/source/browse/src/Google/Api/Ads/AdWords/auth.ini> >>> ? >>> >>> Regards, >>> >>> - Paul, AdWords API Team. >>> >>> On Thursday, 8 August 2013 12:22:57 UTC-4, Jur wrote: >>>> >>>> Hello Alex, >>>> >>>> I've the exact same problem. >>>> Were you able to generate a refresh_token with the GetRefreshToken.php >>>> script? >>>> I was able to do this, but can't get any campaign list visible without >>>> the invalid grant error. >>>> >>>> Did you find a solution? >>>> >>>> Regards, >>>> >>>> Jur >>>> >>>> >>>> Op woensdag 7 augustus 2013 17:11:18 UTC+2 schreef >>>> alexande...@adticket.de: >>>>> >>>>> Hi, >>>>> >>>>> i setted up a PHP script to connect to Adwords API. >>>>> By using the $campaignService->get($selector) method I get always the >>>>> error "invalid_grant". >>>>> Here the Stack Trace: >>>>> >>>>> >>>>> <https://lh3.googleusercontent.com/-0y3vXieQUiE/UgJdrOEATVI/AAAAAAAAAAM/QgXdLHEJCmQ/s1600/Bildschirmfoto+vom+2013-08-07+16%3A41%3A38.png> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> The only thing I found is that for some reason the makeRequest-method >>>>> uses as "grant_type" the value "refresh_token" although i setted the >>>>> value >>>>> "authorization_code". >>>>> >>>>> The version I Used : v201306 >>>>> >>>>> Does anybody know what i'm doing wrong? >>>>> >>>>> P.S. When I use curl on the console I get the access to adwords. >>>>> >>>>> thanks, >>>>> alex >>>>> >>>> -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ Also find us on our blog and discussion group: http://adwordsapi.blogspot.com http://groups.google.com/group/adwords-api =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ You received this message because you are subscribed to the Google Groups "AdWords API Forum" group. To post to this group, send email to adwords-api@googlegroups.com To unsubscribe from this group, send email to adwords-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/adwords-api?hl=en --- You received this message because you are subscribed to the Google Groups "AdWords API Forum" group. To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.