我在 Windows 7 上工作,我正在尝试使用 tweepy 甚至 twitter1.14.2-python 访问 twitter。但我无法破解它。需要帮助。
TWEEPY
import tweepy
OAUTH_TOKEN = "defined here"
OAUTH_SECRET = "defined here"
CONSUMER_KEY = "defined here"
CONSUMER_SECRET = "defined here"
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(OAUTH_TOKEN, OAUTH_SECRET)
api = API.GetUserTimeline(screen_name="yyy")
错误:名称“API”未定义
Twitter 1.14.2
import twitter
from twitter import *
tw = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,CONSUMER_KEY, CONSUMER_SECRET))
tw.statuses.home_timeline()
tw.statuses.user_timeline(screen_name="yyy")
错误:没有名为 OAuth 的模块
我哪里出错了?
最佳答案
因为 tweepy.API 中没有定义/声明 GetUserTimeline
类,因此假设您打算尝试 twitter.Api 的 GetUserTimeline
方法类。
API
通过 twitter.Api
类公开。
创建 twitter.Api
类的实例:
>>> import twitter
>>> api = twitter.Api()
使用登录凭据创建 twitter.Api
实例。
>>> api = twitter.Api(consumer_key='consumer_key',
consumer_secret='consumer_secret', access_token_key='access_token',
access_token_secret='access_token_secret')
获取单个用户的公开状态消息,其中 user
是 Twitter“短名称”或其用户 ID
>>> statuses = api.GetUserTimeline(user)
>>> print [s.text for s in statuses]
关于python - 多次尝试后无法访问推特,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22892640/