Last active
February 8, 2018 16:27
-
-
Save bahorn/b3fd102cca078b31a55e7b75d984b1fe to your computer and use it in GitHub Desktop.
Revisions
-
B Horn renamed this gist
Feb 8, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
B Horn created this gist
Feb 8, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ import os import json import binascii import requests from flask import Flask, request app = Flask(__name__) # Web app to get use a user token from Facebook app_id = "<BLANKED>" app_secret = "<BLANKED>" redirect_uri = "<BLANKED>" def login_uri(client_id, state, version="v2.12"): base = "https://www.facebook.com/{}/dialog/oauth".format(version) scope = ",".join(['manage_pages','publish_pages']) return "{}?client_id={}&redirect_uri={}&state={}&scope={}".format( base, client_id, redirect_uri, state, scope) def get_api_token(code): params = { "client_id":app_id, "client_secret":app_secret, "redirect_uri":redirect_uri, "code":code } print("Yeehah") url = "https://graph.facebook.com/v2.12/oauth/access_token" r = requests.get(url, params=params) return r.json() page = """ <html> <body> <h1>Facebook authorize</h1> <p> <a href="{}">Click here to authorize this app</a> </p> </body> </html> """ @app.route("/") def index_page(): state = binascii.b2a_hex(os.urandom(32)) return page.format(login_uri(app_id,state)) @app.route("/auth") def auth_page(): try: code = request.args.get("code") print(get_api_token(code)) return json.dumps({"status":"ok"}) except: return json.dumps({"status":"failure"})