Created
January 16, 2016 21:38
-
-
Save rberrelleza/cab8a3c6dc74d810967a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import requests | |
import urllib | |
apikey=urllib.unquote("YOUR_KEY") | |
apisecret=urllib.unquote("YOUR_API_SECRET") | |
bearer_creds="{}:{}".format(apikey, apisecret) | |
base64encoded_creds = base64.b64encode(bearer_creds) | |
twitter_api_url="https://api.twitter.com/oauth2/token" | |
headers = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", "Authorization": "Basic {}".format(base64encoded_creds)} | |
response = requests.post( | |
twitter_api_url, | |
data="grant_type=client_credentials", | |
headers=headers) | |
print("Your token is: {}".format(response.json())) | |
# Output would be something like Your token is: | |
# {u'token_type': u'bearer', u'access_token': u'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA%2FAAAAAAAAAAAAAAAAAAAA%3DAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment