March 2019
Beginner
490 pages
12h 40m
English
In this example, we will connect to the Twitter API, which uses the OAuth protocol. You'll need to provide a credentials file with the keys you have taken down from the Twitter app configuration. This is the format of credentials.txt file, where we use a new line for each key or token:
You can find the following code in the twitter_connect.py file:
!/usr/bin/python3import requests, requests_oauthlib, sysdef 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 ...Read now
Unlock full access