我是使用tweetpy发送推文的新手,我按照示例说明,这里解释说我需要从tweeters获取密钥。我这样做并使用此代码为此streamListener建立连接。但是,我只得到一个“错误:401”。欢迎任何想法!谢谢!
from slistener import SListener
import time, tweepy, sys
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''
OAUTH_KEYS = {'consumer_key':CONSUMER_KEY, 'consumer_secret':CONSUMER_SECRET,
'access_token_key':OAUTH_TOKEN, 'access_token_secret':OAUTH_TOKEN_SECRET}
auth = tweepy.OAuthHandler(OAUTH_KEYS['consumer_key'], OAUTH_KEYS['consumer_secret'])
api = tweepy.API(auth)
def main():
track = ['#Matthew', '#HurricaneMatthew']
listen = SListener(api, 'myprefix')
stream = tweepy.Stream(auth, listen)
print "Streaming started..."
try:
stream.filter(track = track, languages=['en'])
except:
print "error!"
stream.disconnect()
if __name__ == '__main__':
main()
答案 0 :(得分:0)
我得到的代码可以在程序中更改这一行。借鉴其他帖子中的见解。
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
# Creation of the actual interface, using authentication
api = tweepy.API(auth)