Hi Danny, 

I'm running into the same problems with regenerating oauth2tokens using a 
refresh token. I tried your code but you have to remove scopes because that 
is only for installed application flow. It throws an error if you the 
scopes withScopes() method because of conflicts. Here's the code I have 
right now:

  
  $oauth2Token = (new OAuth2TokenBuilder())
     ->withClientId($clientId)
     ->withClientSecret($clientSecret)
     ->withRefreshToken($refreshToken)
     ->build();
    $adWordsSession = (new AdWordsSessionBuilder())
     ->withOAuth2Credential($oauth2Token)
     ->withDeveloperToken($developerToken)
     ->build();


When I try to use that adWordsSession to make API calls, I get a bad 
request. The $oauth2Token doesn't contain an accessToken so I'm assuming 
it's not properly generating. Did you ever figure out a solution? It'd be 
nice if the web flow documentation was a bit better.

On Friday, February 10, 2017 at 2:07:31 AM UTC-6, Danny wrote:
>
> Hi Adam
>
> I "think" I might've solved my own issue with the solution I presented 
> where the refresh token is set to the OAuth2 object, which is then passed 
> to the AdWordsSessionBuilder. Based on this, I assume when you use the 
> returned AdWordsSession object to make API calls (containing the refresh 
> token via OAuth2), the API knows to automatically refresh the access token 
> with the given refresh token, so you don't get API call errors due to 
> expired access token.
>
> Although my solution is a bit different, reading the README at 
> https://github.com/googleads/googleads-php-lib and if you're not using 
> adsapi_php.ini, have a look at OAuth2TokenBuilder.php 
> <https://github.com/googleads/googleads-php-lib/blob/master/src/Google/AdsApi/Common/OAuth2TokenBuilder.php>,
>  
> where you can build using withClientId(), withClientSecret() and 
> withRefreshToken(), which I assume is then passed to 
> AdWordsSessionBuilder.php 
> <https://github.com/googleads/googleads-php-lib/blob/master/src/Google/AdsApi/AdWords/AdWordsSessionBuilder.php>
>  via 
> withOAuth2Credential() that you just created.
>
> With some pseudo code, I'm guessing,
>
> $oauth2 =(new OAuth2TokenBuilder())
>     ->withClientId('client_id')  // replace with real values
>     ->withClientSecret('client_secret')  // replace with real values
>     ->withRefreshToken('refresh_token')  // replace with real values
>     ->withScopes('scopes_urls')  // replace with real values
>     ->build();
>
> $session = (new AdWordsSessionBuilder())
>     ->withOAuth2Credential($oauth2)
>     ->withDeveloperToken('dev_token')  // replace with real values
>     ->build();
>
> // make API calls with $session based on 
> https://github.com/googleads/googleads-php-lib#basic-usage
>
> The reason why I'm not using the adsapi_php.ini file is because I'm using 
> the web application flow (not installed app).
>
> On Thursday, 9 February 2017 21:35:46 UTC-8, Adam Haining wrote:
>>
>> I've tried all of this as well, and if I try to force renewing the token 
>> before it expires, it just gives me the current token.  Then after it 
>> expires, I just always get the message:
>> invalid_grant
>> Token has been expired or revoked.
>>
>> Specific examples on how to do this would be greatly appreciated.  I've 
>> attempted using OAuth2TokenRefresher.php as well, no luck.  Thanks!
>>
>> On Thursday, February 9, 2017 at 2:16:37 PM UTC-7, Shwetha Vastrad 
>> (AdWords API Team) wrote:
>>>
>>> Hi Danny,
>>>
>>> You can check if the access token is about to expire and then refresh 
>>> this token as needed. The OAuth2TokenRefresher.php 
>>> <https://github.com/googleads/googleads-php-lib/blob/master/src/Google/AdsApi/Common/Util/OAuth2TokenRefresher.php>
>>>  provides 
>>> functionality to retrieve OAuth2 access tokens and handling refreshing the 
>>> token if it is going to expire. By default, the client libraries 
>>> automatically refresh expired access tokens.
>>>
>>> Regards,
>>> Shwetha, AdWords API Team.
>>>
>>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/f3dea1e3-5efe-407c-9f8b-f995c2c2e9c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to