Simple OAuth2

Need an access token for just yourself? Don't want to fuss around with oauth libraries?

Create a file in the same directory as this code that contains


Then run this script, making sure to specify authorize_url and access_token_url as necessary.

import requests
from credentials import client_id, client_secret
import urllib
from flask import Flask, request
from pprint import pprint

authorize_url = ""
access_token_url = ""

data = {
	"client_id": client_id,
	"redirect_uri": "http://localhost:8080",
	"scope": "",
	"state": "supersecretstate"

print("Go to:")
print("%s?%s" % (authorize_url, urllib.urlencode(data)))
print("Waiting for response...")

app = Flask(__name__)

def get_access_token():
	# parse code
	code = request.args.get('code')
	print code
	data = {
		"client_id": client_id,
		"client_secret": client_secret,
		"code": code
	headers = {
		"Accept": "application/json"
	r =, data=data, headers=headers)
	if r.status_code == 200:
		return str(r.json())

if __name__ == "__main__":'localhost', 8080)
Comments ()