This took me a while to figure out, so I’m sharing it here in case you ever need a Twitter OAUTH2 token (e.g to reenable previews on your HipChat Server)


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'}

Hope it helps!

Build a stride bot in seconds with glitch

After a few months on beta, Stride's developer API is finally open [to the world](https://blog.stride.com/custom-apps-all-aboard-strides-...… Continue reading

Change email in your commit history

Published on July 16, 2017

Automate your lights with openHAB and Alexa

Published on December 10, 2016