Invalid Grant Using Oauth Refresh Token in a Django Web App/Python Client Library

26 views
Skip to first unread message

Jeff

unread,
Jun 1, 2020, 4:08:52 PM6/1/20
to AdWords API and Google Ads API Forum
Hello,

I am putting together a Django web application using the Python client library. I would like users to be able to authenticate and then do stuff.

I have built a web flow and it works fine to get the authorization token. I then use the auth to get a refresh token as such


### Initiates oauth request
auth_code = request.GET['code'] #Grabs auth code
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
os.path.join(os.path.dirname(os.path.dirname(__file__)),'client_secret.json'),
scopes=[oauth2.GetAPIScope('adwords')])
flow.redirect_uri = 'http://127.0.0.1:8000/data'
authorization_url, state = flow.authorization_url(
access_type='offline',
include_granted_scopes='true')

refresh_token = flow.fetch_token(code=auth_code)
credentials = flow.credentials

client = google.ads.google_ads.client.GoogleAdsClient(
credentials, developer_token)


Now I want to build a client using the refresh token. I am passing it using a dict. The token comes back as a string starting with a number and a / followed by a bunch of characters.

I am using the same developer token, client_id and client_secret found in the client_secret.json file.

    def googleAdsClient(refresh_token, developer_token, client_id, client_secret):
       google_credentials = {
       'developer_token': developer_token,
       'refresh_token': refresh_token,
       'client_id': client_id,
       'client_secret': client_secret}
       google_ads_client = GoogleAdsClient.load_from_dict(google_credentials)

Every time I try to make this work I get an invalid_grant response.

Am I missing a step or not fully understanding the concept of what I need to do to get the client working?

Google Ads API Forum Advisor Prod

unread,
Jun 2, 2020, 4:12:45 PM6/2/20
to je...@masondigital.com, adwor...@googlegroups.com
Hi Jeff,

In order to help figure out why you’re receiving an invalid_grant response, could you please privately reply and send the CID and the request ID? With those, I can lookup further information to help understand what’s happening.

Thanks,
Sasha
The Google Ads API Team
 

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