Python 使用Twython正确导航用户推文
我正在尝试使用Twython检索帐户发出的最后一条推文。 我目前的代码是:Python 使用Twython正确导航用户推文,python,twitter,twython,Python,Twitter,Twython,我正在尝试使用Twython检索帐户发出的最后一条推文。 我目前的代码是: try: user_timeline = twitter.get_user_timeline(screen_name='Twitter') except TwythonError as e: print e for tweets in user_timeline: print tweets['text'].encode('utf-8') 然而,虽然我确实获得了所需文本格式的tweet,但我使用的fo
try:
user_timeline = twitter.get_user_timeline(screen_name='Twitter')
except TwythonError as e:
print e
for tweets in user_timeline:
print tweets['text'].encode('utf-8')
然而,虽然我确实获得了所需文本格式的tweet,但我使用的for循环返回了用户最近20条tweet。我只需要用户发出的最后一条推文
我完全不懂Python,因此非常感谢您的帮助。
我很难找到示例代码,因此如果有任何关于该示例代码的指针,我将不胜感激。您必须在调用get\u user\u timeline函数时使用count参数。它应该有效
try:
user_timeline = twitter.get_user_timeline(screen_name='Twitter', count=1)
except TwythonError as e:
print e
for tweets in user_timeline:
print tweets['text'].encode('utf-8')
哪个是当前输出中的第一个,还是最后一个?您可以尝试
tweet=user\u timeline[0];打印tweet['text'].编码('utf-8')
是!这成功了,谢谢你善良的网络陌生人:)