0

Dropbox を使用する完全に自動化されたアプリケーションの場合、「dropboxfs」(「pyfilesystem」を使用する Dropbox FS レイヤー) を使用して Dropbox に自動的にログインする必要があります。コンストラクターが期待する

https://github.com/btimby/fs-dropbox/blob/master/dropboxfs.py#L336

oauth プロセスからのトークン キー + シークレット。

何らかの方法で oauth プロセスを自動化できますか? アプリケーションがブラウザーを起動して oauth ウィンドウを表示したり、oauth アクセス要求を確認する必要がある場所での手動操作は一切行いません。

アプリキー+シークレットは問題ありません。しかし、Dropbox に直接アクセスするために、アプリケーションに Dropbox のユーザー名とパスワードを提供したいだけです。

オプションはありますか?

4

3 に答える 3

1

私は同じ課題に直面し、Splinterと呼ばれる Web アプリケーション用のテスト フレームワークを使用して解決しました。これにより、ブラウザのアクションを自動化できます。ドキュメントページをチェックしてください。

使用したコードは次のとおりです。

from splinter import *
from dropbox import rest, session
from dropbox import client as dbclient
import time

# Initiate Dropbox API
APP_KEY = '###'
APP_SECRET = '###'
ACCESS_TYPE = 'dropbox'
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)
emailDropbox = '###'
passwordDropbox = '###'

request_token = sess.obtain_request_token()

urlDropbox = sess.build_authorize_url(request_token)

def phantomjsOAuth():
    # Target url
    print 'Target url: ', urlDropbox

    browser = Browser('phantomjs')
    print 'Starting phantomjs browser'
    print 'Visiting url'
    browser.visit(urlDropbox)

    # Email form
    print 'Is the email form present? ', browser.is_element_present_by_id('login_email')
    print 'Fill email form'
    browser.find_by_id('email-field').first.find_by_id('login_email').first.fill(emailDropbox)
    print 'Email form successfully filled'

    # Password form
    print 'Is the password form present? ', browser.is_element_present_by_id('login_password')
    print 'Fill password form'
    browser.find_by_id('login_password').first.fill(passwordDropbox)
    print 'Password form successfully filled'

    # Find login submit button
    print 'Is the "Submit" button present?', browser.is_element_present_by_name('login_submit_dummy')
    submitButton = browser.is_element_present_by_name('login_submit_dummy')

    if submitButton == True:
        print 'Pauzing for 5 seconds to avoid clicking errors'
        time.sleep(5)
        print 'Attempting to click the "Submit" button in order to login'
        browser.find_by_name('login_submit_dummy').first.click()
        print '"Submit" button successfully clicked'

        # Allow connection with Dropbox
        print 'Is the "Allow" button present?', browser.is_element_present_by_css('.freshbutton-blue')
        allowButton = browser.is_element_present_by_css('.freshbutton-blue')

        if allowButton == True:
            print 'The "Allow" button is present, attempting to click..'
            browser.find_by_css('.freshbutton-blue').click()
            print 'The "Allow" button is successfully clicked, access to Dropbox is granted.'

            dropboxCode()

        else:
            print 'The "Allow" button is not present, quitting.'
            browser.quit()

    else:
        print 'The "Submit" button was not present, quitting.'
        browser.quit()

def dropboxCode():
    # The rest of the Dropbox code
    # This will fail if the user didn't visit the above URL and hit 'Allow'
    access_token = sess.obtain_access_token(request_token)

    client = dbclient.DropboxClient(sess)
    print "linked account:", client.account_info()

    f = open('working-draft.txt')
    response = client.put_file('/magnum-opus.txt', f)
    print "uploaded:", response

phantomjsOAuth()
于 2013-07-04T13:11:21.617 に答える
0

Dropbox API は現在 OAuth を必要としており、条件はそれを自動化しようとする方法を禁止しています:

https://www.dropbox.com/terms#acceptable_use https://www.dropbox.com/developers/reference/bestpractice

(とにかく、ユーザー名/パスワードをそのように保存したくないはずです。)

于 2013-05-09T16:42:17.680 に答える
-1

OAuth は Dropbox Core API が提供する唯一の認証です。ユーザー名とパスワードを使用してアクセスすることはできません。

于 2013-05-09T16:01:17.217 に答える