def main(argv=sys.argv):
"""
Retrieve and display the access and refresh token.
"""
if len(argv) < 3:
print('CLIENT_ID or CLIENT_SECRET is missing')
return 0
client_id = argv[1]
client_secret = argv[2]
flow = client.OAuth2WebServerFlow(
client_id=client_id,
client_secret=client_secret,
scope=['https://www.googleapis.com/auth/adwords'],
user_agent='Ads Python Client Library',
redirect_uri='urn:ietf:wg:oauth:2.0:oob')
authorize_url = flow.step1_get_authorize_url()
print('Log into the Google Account you use to access your AdWords account'
'and go to the following URL: \n{}\n'.format(authorize_url))
print('After approving the token enter the verification code (if specified).')
code = input('Code: ').strip()
try:
credential = flow.step2_exchange(code)
except client.FlowExchangeError as e:
print('Authentication has failed: {}'.format(e))
sys.exit(1)
else:
print('OAuth 2.0 authorization successful!\n\n'
'Your access token is:\n {}\n\nYour refresh token is:\n {}'.format(
credential.access_token, credential.refresh_token))
评论列表
文章目录