python 需要pip包:requests,requests_oauthlib
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 需要pip包:requests,requests_oauthlib相关的知识,希望对你有一定的参考价值。
import requests
from requests_oauthlib import OAuth1Session
client_key = ''
client_secret = ''
request_token_url = 'https://api.twitter.com/oauth/request_token'
oauth = OAuth1Session(client_key, client_secret=client_secret)
fetch_response = oauth.fetch_request_token(request_token_url)
resource_owner_key = fetch_response.get('oauth_token')
resource_owner_secret = fetch_response.get('oauth_token_secret')
base_authorization_url = 'https://api.twitter.com/oauth/authorize'
authorization_url = oauth.authorization_url(base_authorization_url)
print('Please go here and authorize,', authorization_url)
verifier = input('Authorization PIN: ')
access_token_url = 'https://api.twitter.com/oauth/access_token'
oauth = OAuth1Session(client_key,
client_secret=client_secret,
resource_owner_key=resource_owner_key,
resource_owner_secret=resource_owner_secret,
verifier=verifier)
oauth_tokens = oauth.fetch_access_token(access_token_url)
resource_owner_key = oauth_tokens.get('oauth_token')
resource_owner_secret = oauth_tokens.get('oauth_token_secret')
protected_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'
r = oauth.get(protected_url)
print(r.text)
以上是关于python 需要pip包:requests,requests_oauthlib的主要内容,如果未能解决你的问题,请参考以下文章
python 安装requests需要哪些依赖
python 的pip install 安装包报错。
python2.7.13 怎么pip install 各种包
Python pip 基础命令
python基础:pip和虚拟环境
python安装pip