我正在用 Python 编写一个简单的 Dropbox 应用程序来上传/下载文件。这是我正在使用的特定代码,它创建了与 Dropbox 帐户的连接。
flow = dropbox.client.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 = raw_input("Enter the authorization code here: ").strip()
# This will fail if the user enters an invalid authorization code
access_token, user_id = flow.finish(code)
client = dropbox.client.DropboxClient(access_token)
print 'linked account: ', client.account_info()
f = open('data.txt')
response = client.put_file('/magnum-opus.txt', f)
print 'uploaded: ', response
folder_metadata = client.metadata('/')
print 'metadata: ', folder_metadata
f, metadata = client.get_file_and_metadata('/magnum-opus.txt')
out = open('magnum-opus.txt', 'w')
out.write(f.read())
out.close()
print metadata
它似乎工作正常,但我对检查身份验证的方式持谨慎态度。上面的代码将在用户的默认浏览器中打开一个指向他/她的 Dropbox 帐户的链接,以允许访问此应用程序。但我想跳过这些步骤并获得明确的授权代码。我读过文档,但对我没有帮助。有谁知道如何获取此代码?