Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dropboxlogin
# YOU NEED TO INSERT YOUR APP KEY AND SECRET BELOW!
# Go to dropbox.com/developers/apps to create an app.
from __future__ import absolute_import
from __future__ import print_function
app_key = 'YOUR_APP_KEY'
app_secret = 'YOUR_APP_SECRET'
# access_type can be 'app_folder' or 'dropbox', depending on
# how you registered your app.
access_type = 'app_folder'
import webbrowser
from dropbox import client, rest, session
import keychain
import pickle
import console
def get_request_token():
console.clear()
print('Getting request token...')
sess = session.DropboxSession(app_key, app_secret, access_type)
request_token = sess.obtain_request_token()
request_token.key = request_token.key.decode('ascii')
request_token.secret = request_token.secret.decode('ascii')
url = sess.build_authorize_url(request_token)
console.clear()
webbrowser.open(url, modal=True)
return request_token
def get_access_token():
token_str = keychain.get_password('dropbox', app_key)
if token_str:
key, secret = token_str.split(',')
return session.OAuthToken(key, secret)
request_token = get_request_token()
sess = session.DropboxSession(app_key, app_secret, access_type)
access_token = sess.obtain_access_token(request_token)
key = access_token.key.decode('ascii')
secret = access_token.secret.decode('ascii')
token_str = key + ',' + secret
keychain.set_password('dropbox', app_key, token_str)
return session.OAuthToken(key, secret)
def get_client():
access_token = get_access_token()
sess = session.DropboxSession(app_key, app_secret, access_type)
sess.set_token(access_token.key, access_token.secret)
dropbox_client = client.DropboxClient(sess)
return dropbox_client
def main():
# Demo if started run as a script...
# Just print the account info to verify that the authentication worked:
print('Getting account info...')
dropbox_client = get_client()
account_info = dropbox_client.account_info()
print('linked account:', account_info)
if __name__ == '__main__':
main()
@AG4GitHub

This comment has been minimized.

Copy link

commented Feb 7, 2017

Thanks for this; running the code I receive the following message after sending the authtication code:
object of type nontype has no len()
Any idea what is wrong?

@geekcomputers

This comment has been minimized.

Copy link

commented Oct 10, 2017

This isn't working for me, it runs loads dropbox I get my my code, click on the x paste it into Pythonista then get unexpected EOF whie parsing, if I change input to raw_input I get Error 400 Client Error Bad Request

@geekcomputers

This comment has been minimized.

Copy link

commented Oct 10, 2017

Forgot to add mine does the same as AG4Github above I get that error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.