March 2019
Beginner
490 pages
12h 40m
English
In the previous script, we can add a get_mentions() function for checking and retrieving new tweets from our mentions timeline. For this task, we can use the timeline endpoint at https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-mentions_timeline.html.
You can find the following code in the twitter_mentions.py file:
#! /usr/bin/python3import requestsimport requests_oauthlibimport sysimport jsondef init_auth(file): (CONSUMER_KEY,CONSUMER_SECRET,OAUTH_TOKEN,OAUTH_TOKEN_SECRET) = open(file, 'r').read().splitlines() auth_obj = requests_oauthlib.OAuth1(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) if verify_credentials(auth_obj): print('Validated credentials OK') ...Read now
Unlock full access