我想知道为什么我收到这个错误。这段代码来自我正在上网的课程。我正在将LOCAL_WOE_ID更改为我的本地区域的WOE ID,这是我收到错误的时候。如果我使用一个大城市的ID,似乎没问题。
import pickle
import os
if not os.path.exists('secret_twitter_credentials.pkl'):
Twitter={}
Twitter['Consumer Key'] = '...'
Twitter['Consumer Secret'] = '...'
Twitter['Access Token'] = '...'
Twitter['Access Token Secret'] = '...'
with open('secret_twitter_credentials.pkl','wb') as f:
pickle.dump(Twitter, f)
else:
Twitter=pickle.load(open('secret_twitter_credentials.pkl','rb'))
WORLD_WOE_ID = 1
US_WOE_ID = 23424977
LOCAL_WOE_ID=2344925
# Prefix ID with the underscore for query string parameterization.
# Without the underscore, the twitter package appends the ID value
# to the URL itself as a special case keyword argument.
world_trends = twitter_api.trends.place(_id=WORLD_WOE_ID)
us_trends = twitter_api.trends.place(_id=US_WOE_ID)
local_trends = twitter_api.trends.place(_id=LOCAL_WOE_ID)
我收到这个错误。
TwitterHTTPError: Twitter sent status 404 for URL: 1.1/trends/place.json using parameters: (id=2344925&oauth_consumer_key=...&oauth_nonce=...&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1553037060&oauth_token=...&oauth_version=1.0&oauth_signature=...)
details: {'errors': [{'code': 34, 'message': 'Sorry, that page does not exist.'}]}
这个问题似乎是由于2344925的LOCAL_WOE_ID
对Twitter API无效。
Twitter提供了另一个API twitter.trends.available()
,它提供了所有可用的WOEID列表。 API文档位于:https://developer.twitter.com/en/docs/trends/locations-with-trending-topics/api-reference/get-trends-available.html
2344925没有出现在这个列表中(虽然它可以在其他一些WOEID查找中找到,例如https://www.flickr.com/places/info/2344925),这种差异可能是由于Yahoo!目前没有完全支持他们的“Where On Earth”数据(https://en.wikipedia.org/wiki/WOEID)。
我正在上同一个班级并得到同样的错误。
我找到了一个解决方法。由于雅虎不再提供WOEID,而您只需将其用于Twitter应用程序,那么您可以通过这种方式找到离您最近的城市;跑
twitter_api.trends.available()
在你的jupyter笔记本中(当然在安装和导入twitter之后)。这将为您提供城市列表,您可以为您的ctrl + f。