auto get refresh token in web application

2,113 views
Skip to first unread message

GoldenOfHeart

unread,
Jan 17, 2024, 2:06:49 PM1/17/24
to Google Ads API and AdWords API Forum
Hello. I tryed to connection with Google Api. Problem is that i need to generate refresh token. Currently I do that in this way:
~/go/bin/oauth2l fetch --credentials ~/your_credentials.json --scope cloud-platform
It works but i need do that in a server into Laravel application. How I can do that aotomatically? 

Google Ads API Forum Advisor

unread,
Jan 17, 2024, 6:18:19 PM1/17/24
to golden...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads API support team.

After reviewing your concern, I understand that you want to generate a refresh token automatically on the server. The below approach might address your concern.

  • I would recommend you use the OAuth2 desktop app or web app flow. OAuth2 desktop app and web app flows do require an initial user interaction for granting access to the account.
  • For the OAuth2 desktop app flow, you can persist a refresh token (which never expires) to obtain a new access token whenever necessary. When using one of our client libraries, you can authorize your app by filling out a configuration file.

Also, please check out Choose a user type and publishing status documentation; it will explain how to prevent the refresh token expiration by publishing status to 'In Production'.

I hope this helps. Kindly get back to us if you have any queries related to the Google Ads API. 

This message is in relation to case "ref:!00D1U01174p.!5004Q02rXACE:ref"

Thanks,
 
Google Logo Google Ads API Team


Cristian Andrei Grigore

unread,
Mar 14, 2024, 6:24:12 PM3/14/24
to Google Ads API and AdWords API Forum
How do I get the refresh token (which never expires)? Is this the refresh token yield by Fetch a refresh token?

Google Ads API Forum Advisor

unread,
Mar 15, 2024, 5:23:00 AM3/15/24
to cristianan...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for getting back to us.

Kindly note that however you generate the refresh token, to avoid the refresh token expiring in 7 days go to the Google API Console and navigate to the OAuth consent screen and then change the publishing status to “In production”. If its publishing status is in "In production" already, this means that you have already applied this Setting up your OAuth consent screen instruction to that account that makes the life of the refresh token longer. Also, I would suggest you to refer to the "Configure the OAuth consent screen" documentation to complete this process. Kindly refer to the document Refresh token expiration to get more information. Also, I would suggest you to refer to the Generate tokens guide as it describes how to generate the refresh token using the OAuth2 Playground
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02rXACE:ref" (ADR-00219553)


Thanks,
 
Google Logo Google Ads API Team

 

Reply all
Reply to author
Forward
0 new messages