get_twitter_cred.py 文件源码

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

项目:nsc-cloudproject-s22016 作者: agitaretech 项目源码 文件源码
def get_access_token(consumer_key, consumer_secret):
    oauth_client = OAuth1Session(consumer_key, client_secret=consumer_secret, callback_uri='oob')

    print('Requesting temp token from Twitter')

    try:
        resp = oauth_client.fetch_request_token(REQUEST_TOKEN_URL)
    except ValueError:
        print('Invalid respond from Twitter requesting temp token: %s' % e)
        return
    url = oauth_client.authorization_url(AUTHORIZATION_URL)

    print('')
    print('I will try to start a browser to visit the following Twitter page')
    print('if a browser will not start, copy the URL to your browser')
    print('and retrieve the pincode to be used')
    print('in the next step to obtaining an Authentication Token:')
    print('')
    print(url)
    print('')

    webbrowser.open(url)
    pincode = input('Pincode? ')

    print('')
    print('Generating and signing request for an access token')
    print('')

    oauth_client = OAuth1Session(consumer_key, client_secret=consumer_secret,
                                 resource_owner_key=resp.get('oauth_token'),
                                 resource_owner_secret=resp.get('oauth_token_secret'),
                                 verifier=pincode
    )
    try:
        resp = oauth_client.fetch_access_token(ACCESS_TOKEN_URL)
    except ValueError:
        print('Invalid respond from Twitter requesting access token: %s' % e)
        return

    print('Your Twitter Access Token key: %s' % resp.get('oauth_token'))

    print('          Access Token secret: %s' % resp.get('oauth_token_secret'))
    print('')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号