Refresh Token Auto Update

910 views
Skip to first unread message

Eray Bakır

unread,
Apr 4, 2022, 6:38:31 AM4/4/22
to Google Ads API and AdWords API Forum
Hello, I have a project whose Publishing status is Testing (I am using Google Ads Api).

 //using FileStream stream = new("Credentials.json", FileMode.Open, FileAccess.Read);

                //// The file token.json stores the user's access and refresh tokens, and is created
                //// automatically when the authorization flow completes for the first time.
                //UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                // GoogleClientSecrets.FromStream(stream).Secrets,
                // scopes,
                // "user",
                // CancellationToken.None,
                // new FileDataStore("Token", true)
                //);

                //if (credential.Token.IsExpired(credential.Flow.Clock))
                // await credential.RefreshTokenAsync(CancellationToken.None);

When I use the code above, it expects me to log in via Gmail, but I want to automatically handle the Refresh token and continue uninterrupted requests without understanding anything to the user. I am using Desktop Application as Flow, but I am using Net 5 Api as Framework. I look forward to your help in this matter.

Thank you from now.

Google Ads API Forum Advisor

unread,
Apr 4, 2022, 2:46:10 PM4/4/22
to crazy...@gmail.com, adwor...@googlegroups.com
Hi Eray,

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

You may refer to this document to read more information about refresh token expiration. Since you mentioned that the refresh token expires after 7 days, then it appears that the scenario below is happening at your end.

"A Google Cloud Platform project with an OAuth consent screen configured for an external user type and a publishing status of "Testing" is issued a refresh token expiring in 7 days." As you set the publishing status to "Testing" so the refresh token expires every 7 days and receives an “invalid_grant” error. That being said, please go to the Google API Console and navigate to the OAuth consent screen and then change the publishing status to “In production” to avoid the refresh token expiring in 7 days. Let me know if you have any question.

Thanks,
Google Logo
Nirmita
Google Ads API Team
 


ref:_00D1U1174p._5004Q2ZJSyG:ref
Reply all
Reply to author
Forward
0 new messages