My application is acquiring an access and refresh token for a user's DFP account (using OAuth 2.0 flow with access_type='offline'). The refresh token is being used with the googleads python library (
https://github.com/googleads/googleads-python-lib).
The problem is that the refresh token stops working after about 48 hours (and maybe sooner), and I get back the following response when trying to acquire a new access token using the saved refresh token:
Status code: 400
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
Initially, up to a period of at least 3 hours, the refresh token works as expected, and I get back the following response:
{
"access_token": "[-ed: actual token removed]",
"token_type": "Bearer",
"expires_in": 3600
}
I'm using the following python code to test acquiring a new access token using the refresh token:
import requests
token_url = "
https://www.googleapis.com/oauth2/v3/token"
refresh_token = "xxx"
client_id = "xxx"
client_secret = "xxx"
grant_type = "refresh_token"
response =
requests.post(token_url, dict(
refresh_token=refresh_token,
client_id=client_id,
client_secret=client_secret,
grant_type=grant_type,
))
print response.content
Why does the refresh token apparently expire after a couple of days?