我正在使用oauth2包为django使用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)
但是为了在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' : '',
'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但是没有完成已经完成的工作。
答案 0 :(得分:0)
很抱歉,为什么不在服务器上安装Dropbox客户端并将文件推送到同步文件夹?