2015-02-09 9 views
9

का उपयोग कर ट्विटर डेटा पुनर्प्राप्त करते समय त्रुटि, मैं नीचे दिए गए कोड का उपयोग करके ट्वीपी का उपयोग करके ट्विटर डेटा पुनर्प्राप्त करने का प्रयास कर रहा हूं, लेकिन मैं 401 त्रुटि लौटा रहा हूं, और मैं एक्सेस और गुप्त टोकन को पुन: उत्पन्न करता हूं, और वही त्रुटि दिखाई देती है।401 Tweepy

#imports 
from tweepy import Stream 
from tweepy import OAuthHandler 
from tweepy.streaming import StreamListener 

#setting up the keys 
consumer_key = 'xxxxxxx' 
consumer_secret = 'xxxxxxxx' 
access_token = 'xxxxxxxxxx' 
access_secret = 'xxxxxxxxxxxxx' 

class TweetListener(StreamListener): 
# A listener handles tweets are the received from the stream. 
#This is a basic listener that just prints received tweets to standard output 

    def on_data(self, data): 
     print (data) 
     return True 

    def on_error(self, status): 
     print (status) 



#printing all the tweets to the standard output 
auth = OAuthHandler(consumer_key, consumer_secret) 
auth.set_access_token(access_token, access_secret) 



stream = Stream(auth, TweetListener()) 

t = u"#سوريا" 
stream.filter(track=[t]) 
+0

क्या आपने ऐप को अपने ट्विटर खाते में अधिकृत किया था? [सहायता लिंक] [1] [1]: http://stackoverflow.com/questions/19095257/using-twython-to-send-a-tweet-twitter-api-error/1 9 1 9 6583 # 1 9 1 9 6583 –

+0

असुरक्षित रूप से, मुझे अभी भी एक ही त्रुटि है। – user3643380

+0

मैंने ट्विटर क्षेत्र के साथ साइन इन करने का भी प्रयास किया, लेकिन इसका उपयोग नहीं किया। कोई मदद !!! – user3643380

उत्तर

8

बस अपनी प्रणाली की घड़ी को रीसेट करें।

यदि प्रमाणीकरण के लिए एक एपीआई अनुरोध किसी सर्वर से आता है जो दावा करता है कि यह समय है जो ट्विटर समय के 15 मिनट के बाहर है, तो यह 401 त्रुटि के साथ विफल हो जाएगा।

ThankYou

+0

धन्यवाद मुझे लगता है कि यह वास्तव में 5 है मिनट, 15 मिनट नहीं। साथ ही, यह केवल स्ट्रीमिंग अनुरोधों पर लागू होता है। आरईएसटी एपीआई अनुरोध ठीक काम करेंगे भले ही घड़ी सिंक न हो। – Jonas

3

तुम बस apps.twitter.com पेज से पहुंच टोकन को कॉपी में एक गलती की हो सकता है।

आपको एक्सेस टोकन के रूप में दी गई पूरी चीज़ की प्रतिलिपि बनाने की आवश्यकता है, न केवल - के बाद स्ट्रिंग।

उदाहरण के लिए, संपूर्ण स्ट्रिंग 74376347-jkghdui456hjkbjhgbm45gj जैसे jkghdui456hjkbjhgbm45gj की प्रतिलिपि बनाएँ और पेस्ट करें।

[नोट करें उपर्युक्त स्ट्रिंग केवल कुछ है जिसे मैंने प्रदर्शन उद्देश्य के लिए यादृच्छिक रूप से टाइप किया है। आपका वास्तविक पहुँच टोकन भी हालांकि इस तरह दिखेगा, यानी, ] "नंबर-एक अल्फ़ान्यूमेरिक स्ट्रिंग के एक स्ट्रिंग"

0

तुम सिर्फ दोहरे उद्धरण में अपनी चाबी को दिखाने के लिए है और आप को परिभाषित करने की जरूरत नहीं है अपने अंतिम ट्विटर प्रमाणीकरण में चाबियाँ।

#Import the necessary methods from tweepy library 
from tweepy.streaming import StreamListener 
from tweepy import OAuthHandler 
from tweepy import Stream 

#Variables that contains the user credentials to access Twitter API 
access_token = 'X3YIzD' 
access_token_secret = 'PiwPirr' 

consumer_key = 'ekaOmyGn' 
consumer_secret = 'RkFXRIOf83r' 


#This is a basic listener that just prints received tweets to stdout. 
class StdOutListener(StreamListener): 

def on_data(self, data): 
    print data 
    return True 

def on_error(self, status): 
    print status 


if __name__ == '__main__': 

#This handles Twitter authetification and the connection to Twitter 
Streaming API 
l = StdOutListener() 
auth = OAuthHandler(consumer_key, consumer_secret) 
auth.set_access_token(access_token, access_token_secret) 
stream = Stream(auth, l) 

#This line filter Twitter Streams to capture data by the keywords: 'python', 
'javascript', 'ruby' 
stream.filter(track=['python', 'javascript', 'ruby']) 
0

मेरे मामले में त्रुटि हुई क्योंकि मैं AppAuthHandler बजाय OAuthHandler उपयोग कर रहा था। OAuthHandler पर स्विच करने से समस्या हल हो गई।