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
En esta página del sitio puede ver el video en línea Twitter Streaming API - Python & Code! de Duración hora minuto segunda en buena calidad , que subió el usuario Flavor Of The Month 31 octubre 2016, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 4,817 veces y le gustó 26 a los espectadores. Disfruta viendo!