[英]Using Javascript for Dropbox core api
I am not a js programmer. 我不是JS程序员。 But for some reason, I have to write a js program to get the access token so that the program can use the dropbox core api.
但是由于某种原因,我必须编写一个js程序来获取访问令牌,以便该程序可以使用dropbox核心api。
what I have tried is the following: 我尝试了以下内容:
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://api.dropbox.com/1/oauth/request_token?oauth_consumer_key=qxxxxxxxx&oauth_consumer_secret=axxxxxxxxx", false);
xhr.send();
console.log("status: " + xhr.statusText);
console.log("response: " + xhr.responseText);
This is not work...I need help~ 这不行...我需要帮助〜
response: {"error": "Unauthorized"} this is the error message I received 响应:{“错误”:“未经授权”}这是我收到的错误信息
The call to request_token
has to be signed with OAuth. 对
request_token
的调用必须使用OAuth签名。 You should be passing an Authorization
header that looks something like this (using a PLAINTEXT
signature): 您应该传递一个类似于以下内容的
Authorization
标头(使用PLAINTEXT
签名):
OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="<app key>", oauth_signature="<app secret>&"
But, before you go down this path, you should really use OAuth 2 instead. 但是,在走这条路之前,您应该真正使用OAuth 2。 It's simpler than OAuth 1. The only reason I can see to use OAuth 1 is if you're app can't be hosted on HTTPS.
它比OAuth 1简单。我能看到使用OAuth 1的唯一原因是,如果您的应用程序无法托管在HTTPS上。 (OAuth 2 requires an HTTPS redirect URI.)
(OAuth 2需要HTTPS重定向URI。)
And, before you build that all by hand, you should just use dropbox-js . 并且,在手动构建所有功能之前,应该只使用dropbox-js 。 Then your code would be something like this:
然后您的代码将如下所示:
var client = new Dropbox.Client({key: '<app secret>'});
client.authenticate();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.