使用tweepy获取热门话题的python错误

时间:2014-06-03 02:59:53

标签: python tweepy

我试图通过基于Tweepy库的twitter api获得前20个热门话题。

这是我的python代码:

import tweepy
import json
import time

today = time.strftime("%Y-%m-%d")

CONSUMER_KEY = ""
CONSUMER_SECRET = ""

ACCESS_KEY = ""
ACCESS_SECRET = ""

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

trends = api.trends_daily(today)
print trends

我正在使用trends_daily函数来获取每天的前20个主题。

变量"今天"是日期格式today = time.strftime("%Y-%m-%d")。我也试过字符串格式。但是,它会保留报告错误消息:

File "/Users/Ivy/PycharmProjects/TwitterTrend/trends.py", line 17, in <module>
    trends = api.trends_daily("2014-06-03")
  File "build/bdist.macosx-10.9-intel/egg/tweepy/binder.py", line 230, in _call
  File "build/bdist.macosx-10.9-intel/egg/tweepy/binder.py", line 203, in execute
tweepy.error.TweepError: [{u'message': u'Sorry, that page does not exist', u'code': 34}] 

1 个答案:

答案 0 :(得分:2)

我相信您使用的是no longer supported https://api.twitter.com/1/trends/daily.json的推文版本:https://api.twitter.com/1.1/trends/available.json

尝试重新安装(版本1.1),例如: {{3}}