【问题标题】:Tweepy in python 2.7 Auth for streamlistener, receives error 401 as responsepython 2.7 Auth for streamlistener 中的 Tweepy,收到错误 401 作为响应
【发布时间】:2016-10-06 05:12:53
【问题描述】:

我是使用 tweetpy 流式传输推文的新手。我这样做并使用此代码为此 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()

【问题讨论】:

    标签: python-2.7 tweepy


    【解决方案1】:

    我得到了代码来改变程序中的这些行。结合其他帖子中的见解。

    # 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-11
      • 1970-01-01
      • 2022-10-16
      • 1970-01-01
      • 2018-06-23
      • 2018-08-31
      • 2018-05-26
      • 2018-01-06
      相关资源
      最近更新 更多