아래 프로그램을 실행하고 있습니다. 아래 오류 메시지가 표시됩니다. 401 **** 401 **** 이tweepy를 사용하는 동안 401 오류가 발생했습니다.
(일부 포럼에서 가져온) 코드는 기본적으로 트위터에 연결하고 트윗을 가져 오기 위해 시도 (반복에 계속). 우분투 터미널에서 실행되었을 때 401 오류 메시지가 나타납니다.
import sys
import json
import pymongo
import tweepy
consumer_key="XX" ##all the keys and codes have to be strings
consumer_secret="XX"
access_token = "XX"
access_token_secret = "XX"
# This is the listener, resposible for receiving data
class StdOutListener(tweepy.StreamListener):
def on_data(self, data):
# Twitter returns data in JSON format - we need to decode it first
decoded = json.loads(data)
# Also, we convert UTF-8 to ASCII ignoring all bad characters sent by users
print '@%s: %s' % (decoded['user']['screen_name'], decoded['text'].encode('ascii', 'ignore'))
print ''
return True
def on_error(self, status):
print status
if __name__ == '__main__':
l = StdOutListener()
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
print "Showing all new tweets for #programming:"
# There are different kinds of streams: public stream, user stream, multi-user streams
# In this example follow #programming tag
# For more details refer to https://dev.twitter.com/docs/streaming-apis
stream = tweepy.Stream(auth, l)
stream.filter(track=['programming'])
정확한 소비자/액세스 토큰을 사용하고 있습니까? "some forum"또는 "XX"'의 사람들뿐 아니라? – Luigi
트위터 개발자 사이트에서 생성 된 올바른 것들을 사용하고 있습니다 –