Python dropbox.DropboxOAuth2FlowNoRedirect() Examples

The following are 2 code examples of dropbox.DropboxOAuth2FlowNoRedirect(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module dropbox , or try the search function .
Example #1
Source File: application.py    From spellbook with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
def command_dropbox_connect(args):
    import dropbox

    if args.spellbook_name is not None:
        print('ERR: sync is only for all books')
        return

    app_key = 'ow3gosk8pb9bhkr'
    app_secret = 'w3eqoqx5scb64pd'
    flow = dropbox.DropboxOAuth2FlowNoRedirect(app_key, app_secret)
    # Have the user sign in and authorize this token
    authorize_url = flow.start()
    print('1. Go to: ' + authorize_url)
    print('2. Click "Allow" (you might have to log in first)')
    print('3. Copy the authorization code.')
    code = collect_str("the authorization code here")

    # This will fail if the user enters an invalid authorization code
    access_token, user_id = flow.finish(code)

    client = dropbox.Dropbox(access_token)
    print('successfully linked account: ', client.users_get_current_account().name.display_name)
    with open(DROPBOX_TOKEN_PATH, 'w') as fout:
        fout.write(access_token) 
Example #2
Source File: dropbox.py    From paper-to-git with Apache License 2.0 6 votes vote down vote up
def get_new_auth_token(self):
        # Run the dropbox OAuth Flow to get the user's OAuth Token.
        auth_flow = DropboxOAuth2FlowNoRedirect(config.dropbox.app_key,
                                                config.dropbox.app_secret)
        authorize_url = auth_flow.start()
        print("1. Go to: " + authorize_url)
        print("2. Click \"Allow\" (you might have to log in first).")
        print("3. Copy the authorization code.")
        auth_code = input("Enter the authorization code here: ").strip()

        try:
            oauth_result = auth_flow.finish(auth_code)
        except Exception as e:
            print('Error: %s' % (e,))
            return

        config.write_to_user_config('dropbox', 'api_token',
                                    oauth_result.access_token)
        return oauth_result.access_token