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

1 投票
1 回答
568 浏览
提问于 2025-04-18 08:21

我正在尝试通过Twitter的API,使用Tweepy库获取前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”的格式是日期格式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 个回答

2

我觉得你正在使用的是tweepy的1.0版本,这个版本已经不再支持了:https://dev.twitter.com/docs/api/1/get/trends/daily

建议你重新安装一下(1.1版本),比如说可以用这个链接: https://api.twitter.com/1.1/trends/available.json

撰写回答