CODE POSTED BELOW! Click "show more"
Python 3.4 (probably compatible with other versions)
Original Guide & extra Python program options (3rd party website):
http://adilmoujahid.com/posts/2014/07...
Follow the Twitter API instructions on the guide above. This link will point you to where you'll need to set up a free Twitter account and get access to their free Twitter Python streaming API.
/ overview
The Code! Be sure to change the "APIrelatedkeys" to your API keys from Twitter Streaming API:
#Import the necessary methods from tweepy library
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import json
#Variables that contains the user credentials to access Twitter API
access_token = "APIrelatedkeys"
access_token_secret = "APIrelatedkeys"
consumer_key = "APIrelatedkeys"
consumer_secret = "APIrelatedkeys"
#This is a basic listener that just prints received tweets to stdout.
class StdOutListener(StreamListener):
def on_data(self, data):
decoded = json.loads(data)
print (decoded['user']['screen_name'], decoded['text'].encode('ascii', 'ignore'))
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 keyword: 'python'
stream.filter(track=['python'])
0:00 - Introduction to setting up Twitter streaming API via Python
0:24 - Setting up a Twitter streaming API account and obtaining API keys
1:36 - Code modification for cleaner tweet output
2:10 - Customizing search keywords in the program
2:32 - Running the program and concluding remarks
In questa pagina del sito puoi guardare il video online Twitter Streaming API - Python & Code! della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Flavor Of The Month 31 ottobre 2016, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 4,817 volte e gli è piaciuto 26 spettatori. Buona visione!