【发布时间】:2017-03-30 18:20:15
【问题描述】:
我正在制作一个小型 Python 脚本,以递归方式列出用户 Dropbox 帐户中的所有文件。 OAuth2.0 流程有效,但我在另一个调用 list_folder 方法以列出这些文件/文件夹时进行了 frankensteining。
我被困在 22 点,我需要提供 OAuth 流返回的访问令牌。我可以调用什么来返回令牌?
(或者,你知道一个快速的 python 脚本已经可以满足我的要求)
from dropbox.client import DropboxOAuth2FlowNoRedirect, DropboxClient
from dropbox import rest as dbrest
import requests
import json
auth_flow = DropboxOAuth2FlowNoRedirect('<APP_KEY>', '<APP_SECRET>')
###These are filled out in my code, but I hid them here.
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 = raw_input("Enter the authorization code here: ").strip()
try:
oauth_result = auth_flow.finish(auth_code)
except dbrest.ErrorResponse, e:
print('Error: %s' % (e,))
url = "https://api.dropboxapi.com/2/files/list_folder"
headers = {
"Authorization": "Bearer <ACCESS_TOKEN>",
"Content-Type": "application/json"
}
data = {
"path": "",
"recursive": True,
"include_media_info": True,
"include_deleted": True
}
r = requests.post(url, headers=headers, data=json.dumps(data))
print(r.text)
【问题讨论】:
标签: python oauth-2.0 dropbox-api