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
Auf dieser Seite können Sie das Online-Video Twitter Streaming API - Python & Code! mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Flavor Of The Month 31 Oktober 2016 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 4,817 Mal angesehen und es wurde von 26 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!