cli.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:adwordspy 作者: MihaZelnik 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号