通过 django 使用 dropbox api 将文件推送到 dropbox
我正在使用 django 的 oauth2 包来使用 dropbox 来推送文件: 为了检索帐户信息,此签名方法有效:
parameters = {
'oauth_consumer_key' : DropboxConstants.app_key,
'oauth_token' : dropbox.oauth_token,
'oauth_signature_method': oauth.SignatureMethod_HMAC_SHA1.name,
'oauth_timestamp' : oauth.generate_timestamp(),
'oauth_nonce' : oauth.generate_nonce(),
'oauth_version' : DropboxConstants.api_version,
'oauth_signature' : ''
}
access_token_g = oauth.Token(key=dropbox.oauth_token,secret=dropbox.oauth_token_secret)
#prepare signature
oauth_request = oauth.Request(method="GET",url=DropboxConstants.account_info_url,parameters=parameters)
signature_method_m = oauth.SignatureMethod_HMAC_SHA1()
oauth_request.sign_request(signature_method=signature_method_m,
consumer=DropboxConstants.consumer,
token=access_token_g)
resp, content = DropboxConstants.client.request(oauth_request.to_url())
if resp['status'] != '200':
print content
raise Exception("Invalid response from Dropbox.")
account_info = simplejson.loads(content)
但是对于我正在使用的保管箱上推送文件:
parameters = {
'oauth_consumer_key' : DropboxConstants.app_key,
'oauth_token' : dropbox.oauth_token,
'oauth_signature_method': oauth.SignatureMethod_HMAC_SHA1.name,
'oauth_timestamp' : oauth.generate_timestamp(),
'oauth_nonce' : oauth.generate_nonce(),
'oauth_version' : DropboxConstants.api_version,
'oauth_signature' : '',
'file' : request.FILES['file'].name,
}
access_token_g = oauth.Token(key=dropbox.oauth_token,secret=dropbox.oauth_token_secret)
#prepare signature
oauth_request = oauth.Request(method="POST",
url=DropboxConstants.file_access_url,
parameters=parameters)
signature_method_m = oauth.SignatureMethod_HMAC_SHA1()
oauth_request.sign_request(signature_method=signature_method_m,
consumer=DropboxConstants.consumer,
token=access_token_g)
resp, content = DropboxConstants.client.request(oauth_request.to_url())
if resp['status'] != '200':
print content
raise Exception("Invalid response from Dropbox.")
它给了我这个错误
{"error": "Invalid signature. Expected signature base string: GET&https%3A%2F%2Fapi-content.dropbox.com%2F0%2Ffiles%2Fdropbox%2F&oauth_body_hash%3D2jmj7l5rSw0yVb%252FvlWAYkK%252FYBwk%253D%26oauth_consumer_key%3Dedw6k7d78hu8q8v%26oauth_nonce%3D69188147%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1314863397%26oauth_token%3Dv0b6uxv18z2wrmg%26oauth_version%3D1.0"}
signature that is generated is:
AUHJv%2F%2BCeRP27PsJ1X5eMaSghGU%3D
我遇到了一篇文章:https://github.com/ourbricks/ourbricks-api-examples/blob/master/python/upload2ourbricks.py#L126-173 但没有得到已经完成的事情。
i am using oauth2 package for django to use dropbox as for pushing file:
for retrieving account info this signature method works:
parameters = {
'oauth_consumer_key' : DropboxConstants.app_key,
'oauth_token' : dropbox.oauth_token,
'oauth_signature_method': oauth.SignatureMethod_HMAC_SHA1.name,
'oauth_timestamp' : oauth.generate_timestamp(),
'oauth_nonce' : oauth.generate_nonce(),
'oauth_version' : DropboxConstants.api_version,
'oauth_signature' : ''
}
access_token_g = oauth.Token(key=dropbox.oauth_token,secret=dropbox.oauth_token_secret)
#prepare signature
oauth_request = oauth.Request(method="GET",url=DropboxConstants.account_info_url,parameters=parameters)
signature_method_m = oauth.SignatureMethod_HMAC_SHA1()
oauth_request.sign_request(signature_method=signature_method_m,
consumer=DropboxConstants.consumer,
token=access_token_g)
resp, content = DropboxConstants.client.request(oauth_request.to_url())
if resp['status'] != '200':
print content
raise Exception("Invalid response from Dropbox.")
account_info = simplejson.loads(content)
But for pushing file on dropbox i am using:
parameters = {
'oauth_consumer_key' : DropboxConstants.app_key,
'oauth_token' : dropbox.oauth_token,
'oauth_signature_method': oauth.SignatureMethod_HMAC_SHA1.name,
'oauth_timestamp' : oauth.generate_timestamp(),
'oauth_nonce' : oauth.generate_nonce(),
'oauth_version' : DropboxConstants.api_version,
'oauth_signature' : '',
'file' : request.FILES['file'].name,
}
access_token_g = oauth.Token(key=dropbox.oauth_token,secret=dropbox.oauth_token_secret)
#prepare signature
oauth_request = oauth.Request(method="POST",
url=DropboxConstants.file_access_url,
parameters=parameters)
signature_method_m = oauth.SignatureMethod_HMAC_SHA1()
oauth_request.sign_request(signature_method=signature_method_m,
consumer=DropboxConstants.consumer,
token=access_token_g)
resp, content = DropboxConstants.client.request(oauth_request.to_url())
if resp['status'] != '200':
print content
raise Exception("Invalid response from Dropbox.")
it gives me this error
{"error": "Invalid signature. Expected signature base string: GET&https%3A%2F%2Fapi-content.dropbox.com%2F0%2Ffiles%2Fdropbox%2F&oauth_body_hash%3D2jmj7l5rSw0yVb%252FvlWAYkK%252FYBwk%253D%26oauth_consumer_key%3Dedw6k7d78hu8q8v%26oauth_nonce%3D69188147%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1314863397%26oauth_token%3Dv0b6uxv18z2wrmg%26oauth_version%3D1.0"}
signature that is generated is:
AUHJv%2F%2BCeRP27PsJ1X5eMaSghGU%3D
I have come across a post: https://github.com/ourbricks/ourbricks-api-examples/blob/master/python/upload2ourbricks.py#L126-173 but didnt get what has been done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,为什么不在服务器上安装 Dropbox 客户端并将文件推送到其同步文件夹呢?
Sorry for asking, why don't you simply install Dropbox client on the server and push the files to its sync folder?