此代码来自我正在上的在线课程。我还注册了一个Twitter开发人员帐户,他们已经批准了该帐户。我已经按照指示创建了一个应用。现在,当我尝试在插入密钥和秘密密钥后运行此代码时,出现401 http错误。访问twitter API需要什么身份验证?
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)
然后我得到以下错误:
{'errors': [{'code': 32, 'message': 'Could not authenticate you.'}]}
如果我是访问API的初学者,那么如果有人解释该怎么做真的很有帮助。