March 2019
Beginner
490 pages
12h 40m
English
We can use the tweepy library to connect to the Twitter API. In this example, we will use a streaming API to process data in real time.
In the same way as we have done before with the Twitter module, we can create our function for connecting with OAuth credentials:
def twitter_connection(file): '''Create the object from which the Twitter API will be consumed, reading the credentials from a file, defined in path parameter.''' (CONSUMER_KEY,CONSUMER_SECRET,OAUTH_TOKEN,OAUTH_TOKEN_SECRET) = open(file, 'r').read().splitlines() # We instanced the authorization manager auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET) auth.set_access_token(OAUTH_TOKEN,OAUTH_TOKEN_SECRET) return (tweepy.API(auth), auth)
The first ...
Read now
Unlock full access