Skip to content

Instantly share code, notes, and snippets.

@prs-watch
Last active October 22, 2017 15:48
Show Gist options
  • Select an option

  • Save prs-watch/ff6933308611a07c14d858fbd1013272 to your computer and use it in GitHub Desktop.

Select an option

Save prs-watch/ff6933308611a07c14d858fbd1013272 to your computer and use it in GitHub Desktop.
A script to create Dropbox OAuth Access Token.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import webbrowser
def create_dropbox_access_token():
"""
access dropbox.
"""
# set variables
code_url = 'https://www.dropbox.com/oauth2/authorize'
access_token_url = 'https://api.dropboxapi.com/oauth2/token'
code_params = {
'response_type' : 'code'
, 'client_id' : '${client_id}'
}
access_token_params = {
'code' : 'none'
, 'grant_type' : 'authorization_code'
, 'client_id' : '${cliend_id}'
, 'client_secret': '${client_secret}'
}
# get code.
res = requests.get(code_url,params=code_params)
webbrowser.open(res.url)
code = input('code:')
access_token_params['code'] = code
# get access token.
post = requests.post(access_token_url,params=access_token_params)
json = post.json()
return json['access_token']
if __name__ == '__main__':
create_dropbox_access_token()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment