I'm trying to access adwords api on behalf of customer using this
tutorial
https://github.com/googleads/googleads-python-lib/wiki/API-access-on-behalf-of-your-clients-(web-flow)
I have already registered my app at google console and have my client_id,
client_secret and redirect_uri.
Here is code:
flow = client.OAuth2WebServerFlow(
client_id=g_appID,
client_secret=g_secret,
scope=oauth2.GetAPIScope('adwords'),
user_agent='Pata',
redirect_uri='http://patarator.pythonanywhere.com/get_Gtoken')
code = request.args['code']
credentials = flow.step2_exchange(code)
print credentials.to_json()
oauth2_client = oauth2.GoogleRefreshTokenClient(
credentials.client_id, credentials.client_secret, credentials.refresh_token)
adwords_client = adwords.AdWordsClient(g_devToken, oauth2_client)
The problem in credentials.refresh_token - it is always null:
{"_module": "oauth2client.client", "scopes":
["https://www.googleapis.com/auth/adwords"], "token_expiry":
"2017-02-28T13:48:42Z", "id_token": null, "access_token":
"******some_access_token*******", "token_uri":
"https://accounts.google.com/o/oauth2/token", "invalid": false,
"token_response": {"access_token": "******some_access_token*******",
"token_type": "Bearer", "expires_in": 3600}, "client_id":
"****my_client_id****", "token_info_uri":
"https://www.googleapis.com/oauth2/v2/tokeninfo", "client_secret":
"****my_secret****", "revoke_uri":
"https://accounts.google.com/o/oauth2/revoke", "_class": "OAuth2Credentials",
"refresh_token": null, "user_agent": "Pata"}
As refresh_token is null interpreter rises error in line adwords_client =
adwords.AdWordsClient(g_devToken, oauth2_client) with folowwing error log:
File "/home/patarator/comparator/comparator.py", line 195, in get_Gtoken
2017-02-28 13:16:01,446 : adwords_client = adwords.AdWordsClient(g_devToken,
oauth2_client)
2017-02-28 13:16:01,446 : File
"/home/patarator/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/googleads/adwords.py",
line 316, in __init__
2017-02-28 13:16:01,446 : self.oauth2_client.Refresh()
2017-02-28 13:16:01,446 : File
"/home/patarator/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/googleads/oauth2.py",
line 158, in Refresh
2017-02-28 13:16:01,446 : self.proxy_config.disable_certificate_validation)))
2017-02-28 13:16:01,446 : File
"/home/patarator/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/oauth2client/client.py",
line 633, in refresh
2017-02-28 13:16:01,446 : self._refresh(http.request)
2017-02-28 13:16:01,446 : File
"/home/patarator/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/oauth2client/client.py",
line 842, in _refresh
2017-02-28 13:16:01,446 : self._do_refresh_request(http_request)
2017-02-28 13:16:01,446 : File
"/home/patarator/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/oauth2client/client.py",
line 874, in _do_refresh_request
2017-02-28 13:16:01,446 : self.token_uri, method='POST', body=body,
headers=headers)
2017-02-28 13:16:01,446 : File
"/home/patarator/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/httplib2/__init__.py",
line 1659, in request
2017-02-28 13:16:01,446 : (response, content) = self._request(conn,
authority, uri, request_uri, method, body, headers, redirections, cachekey)
2017-02-28 13:16:01,446 : File
"/home/patarator/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/httplib2/__init__.py",
line 1399, in _request
2017-02-28 13:16:01,446 : (response, content) = self._conn_request(conn,
request_uri, method, body, headers)
2017-02-28 13:16:01,447 : File
"/home/patarator/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/httplib2/__init__.py",
line 1355, in _conn_request
2017-02-28 13:16:01,447 : response = conn.getresponse()
2017-02-28 13:16:01,447 : File "/usr/lib/python2.7/httplib.py", line 1039, in
getresponse
2017-02-28 13:16:01,447 : raise ResponseNotReady()
2017-02-28 13:16:01,447 :ResponseNotReady
I'm confused, because that code worked fine when i tested it on localhost.
The only difference is redirect_uri is now ''
http://patarator.pythonanywhere.com/get_Gtoken'' instead of "
http://127.0.0.1:5000/get_Gtoken" ... and with localhost I used another
apptype - Installed Application (there was no redirect_uri field in google
console, only client_id and client_secret).
How should I correctly get that refresh_token?
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/06ff10f0-d85c-4b89-a454-3022fd52a065%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.