This github issue seems related to the problem I 
have: https://github.com/googleads/googleads-php-lib/issues/180

The answer seems to imply that an OAuth2 object should be instantiated and 
not use the OAuth2TokenBuilder (There is a way to set access_token 
with OAuth2 but not with OAuth2TokenBuilder). But still, the app has no way 
to synchronize the access_token refresh part, which is important in a 
distributed system as multiple instances of php on different servers can 
refresh the access token at the same time and I'd like to have a way to 
synchronize the refresh here. (My app was taking care of this before, using 
a redis distributed lock mechanism so I was in control of refreshing and 
updating/saving the new access_token).

I'm wondering if having my own object implementing the 
"FetchAuthTokenInterface" is the solution here. This seems a bit complex 
but maybe this is the way to go?

Thanks.

Le dimanche 7 janvier 2018 10:44:44 UTC-8, Jean-Fabrice Rabaute a écrit :
>
> Hi,
>
> I'm working on migrating from the old api to the new one and I don't 
> understand how to reuse the "access_token".
>
> When using OAuth2TokenBuilder and AdWordsSessionBuilder, I can set the 
> "refresh_token" but not the "access_token".
> If I understand correctly, setting only the refresh_token will force to 
> get a new access_token everytime I create a new instance of 
> OAuth2TokenBuilder (which is instantiating a UserRefreshCredentials object 
> when the ->build() method is called in my case).
> This probably works (not sure there might be race condition with multiple 
> requests in // and then one access_token might be invalid), but this means 
> that an access_token will be fetched everytime, so two http requests 
> instead of one.
> When I have an access_token which is valid for 3600 seconds, I'd like to 
> be able to reuse it for the valid period, but I can't as there is no method 
> in OAuth2TokenBuilder nor UserRefreshCredentials to set the "access_token" 
> when I instantiate my objects on new client http requests.
>
> In your response, you say "The first section builds OAuth2 access token 
> fetchers, which will get access tokens as and when required". But how can 
> this happen if the access_token is not provided? As it is not provided, a 
> new http request needs to be done to get one before doing the adwords api 
> request, right?
>
> In the old API, passing the "refresh_token" AND "access_token" was done 
> when instantiating the AdwordsUser object (here: 
> https://github.com/googleads/googleads-php-lib/blob/deprecated/src/Google/Api/Ads/AdWords/Lib/AdWordsUser.php#L92
>  
> ). It was then possible to reuse an existing and still active 
> "access_token".
> Now, I really can't see how to reuse an existing "access_token" with the 
> new api, only the "refresh_token".
>
> Am I missing something?
>
> Thank you for any help/feedback.
>
> PS: My next problem is to detect that those object are effectively 
> refreshing the access_token because I'd like to update/save/cache the new 
> one to be able to reuse it again for the active time period (usually one 
> hour). That will probably be my next question. The new api seem very weird 
> in this regard. The google/google-auth-library-php (which is used by the 
> adwords library) seem to have the same problem (The app is unable to 
> get/cache/manage the access_token in an easy way).
>
> Le lundi 28 août 2017 09:31:27 UTC-7, Shwetha Vastrad (AdWords API Team) a 
> écrit :
>>
>> Hi Tim, 
>>
>> You need to use OAuth2TokenBuilder 
>> <https://github.com/googleads/googleads-php-lib/blob/master/src/Google/AdsApi/Common/OAuth2TokenBuilder.php#L67>
>>  
>> and AdWordsSessionBuilder 
>> <https://github.com/googleads/googleads-php-lib/blob/master/src/Google/AdsApi/AdWords/AdWordsSessionBuilder.php#L104>
>>  
>> to pass the values programmatically. 
>>
>>     $oAuth2Credential = (new OAuth2TokenBuilder())
>>       ->withClientId("OAUTH_2_CLIENT_ID")
>>       ->withClientSecret("OAUTH_2_CLIENT_SECRET")
>>       ->withRefreshToken("REFRESH_TOKEN")
>>       ->build();
>>
>>     // Construct an API session configured from the OAuth2 credentials 
>> above.
>>     $session = (new AdWordsSessionBuilder())
>>         ->withDeveloperToken("DEVELOPER_TOKEN")
>>         ->withOAuth2Credential($oAuth2Credential)
>>         ->withClientCustomerId("CLIENT_CUSTOMER_ID")
>>         ->build();
>>
>>
>> The first section builds OAuth2 access token fetchers, which will get 
>> access tokens as and when required. You need to use the oAuth2Credential 
>> object when you build a AdsSession in the PHP client library. I hope this 
>> helps. If you have any further questions, I would suggest that you post on 
>> the library's issue tracker 
>> <https://github.com/googleads/googleads-php-lib/issues> so the library 
>> owners can help you out. 
>>
>> 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 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.
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/a46c6e5b-9df6-4574-af05-151cbed6e6aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • Re: ... Jean-Fabrice Rabaute
    • ... Jean-Fabrice Rabaute
      • ... 'Vincent Racaza (AdWords API Team)' via AdWords API Forum
        • ... Jean-Fabrice Rabaute
          • ... 'Josh Radcliff (AdWords API Team)' via AdWords API Forum
    • ... 'Thanet Knack Praneenararat (AdWords API Team)' via AdWords API Forum
      • ... Jean-Fabrice Rabaute
        • ... 'Thanet Knack Praneenararat (AdWords API Team)' via AdWords API Forum
          • ... Jean-Fabrice Rabaute
            • ... 'Thanet Knack Praneenararat (AdWords API Team)' via AdWords API Forum

Reply via email to