Last active
August 29, 2015 14:27
-
-
Save lozhn/5e083ceaea513d457753 to your computer and use it in GitHub Desktop.
get VK Api Token with bottle
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 json | |
import requests | |
from bottle import route, run, redirect, request | |
APP_ID = YOUR APP ID | |
APP_SECRET = YOUR APP SECRET | |
SCOPE = YOUR APP SCOPE (e.g. 'photos,groups,offline') | |
REDIRECT_URI = YOUR APP OPEN API HOST (e.g. 'http://localhost:8080/auth') | |
TOKEN = '' | |
@route('/') | |
def index(): | |
return redirect('https://oauth.vk.com/authorize?client_id=%s&scope=%s&redirect_uri=%s&response_type=code' % (APP_ID, SCOPE, REDIRECT_URI)) | |
@route('/auth') | |
def code(): | |
code = request.params['code'] | |
token_url = 'https://oauth.vk.com/access_token?client_id=%s&client_secret=%s&code=%s&redirect_uri=%s' % (APP_ID,APP_SECRET, code, REDIRECT_URI) | |
r = requests.get(token_url) | |
token = r.json() | |
TOKEN = token['access_token'] | |
# Final TOKEN. | |
return TOKEN | |
run(host='0.0.0.0', port=8080) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tested with Python3.4