Skip to content

Instantly share code, notes, and snippets.

@lozhn
Last active August 29, 2015 14:27
Show Gist options
  • Save lozhn/5e083ceaea513d457753 to your computer and use it in GitHub Desktop.
Save lozhn/5e083ceaea513d457753 to your computer and use it in GitHub Desktop.
get VK Api Token with bottle
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)
@lozhn
Copy link
Author

lozhn commented Aug 17, 2015

tested with Python3.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment