Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Error 400: invalid_request on generated Refresh Tokens

Hi,

 

I am trying to generate YouTube OAuth Refresh Tokens that never expire. Our Youtube application is currently in production, however, when we tried to generate the token by using the following python script and open the verification link in our browser to get authorization code manually, we have received Access blocked Error 400: invalid_request. This script works successfully if I change my application to TESTING mode.

 

flow = InstalledAppFlow.from_client_secrets_file(

    "youtube/secrets.json", youtube_scopes)

)

creds = flow.run_console()

 

Screenshot 2024-11-13 at 6.01.36 PM.png

 

For my understanding, I need to change the application status from TESTING to PRODUCTION mode in order to get the refresh tokens that never expire. Do I need to change the  

redirect_uris to fix this error? What is the best approach to generate OAuth Refresh Tokens that never expire?
 
According to the document https://developers.google.com/identity/protocols/oauth2#:~:text=There%20is%20currently%20a%20limit%2.... , "There is currently a limit of 100 refresh tokens per Google Account per OAuth 2.0 client ID. If the limit is reached, creating a new refresh token automatically invalidates the oldest refresh token without warning. This limit does not apply to service accounts.", does this apply to the application in production mode?

 

Thank you for your support!

0 1 211
1 REPLY 1

Hi @fcarety,

Welcome to the Google Cloud Community!

Just a heads up, YouTube isn’t technically considered part of the Google Cloud product lineup, so I suggest reposting your question on the YouTube community or on Stack Overflow with the youtube-api, youtube-data-api, and youtube-v3-api tags instead.

OAuth 2.0 has short-lived tokens and long-lived tokens. For your specific use case, you’d want to use a long-lived refresh token. To learn how to generate a long-lived refresh token for your application, follow this guide from the YouTube developer site.

Your application could encounter an error due to several possible reasons. Refer to the list of descriptions for the error code 400 for more information.

If you need more assistance with your application, follow these OAuth 2.0 flows based on your use case. You may also check out our code snippets for Python for more examples.

I hope this helps!