从浏览器访问 Dropbox 应用程序
Accessing Dropbox app from browser
我正在尝试从本地主机上的网页 运行 测试连接到 Dropbox 应用程序(在我的帐户上创建)。我选择生成授权代码而不是使用重定向。当我尝试访问应用程序文件夹的元数据时,代码页 (https://www.dropbox.com/1/oauth2/authorize_submit) 上生成和显示的任何代码似乎都会在控制台中产生错误:
window.open('https://www.dropbox.com/1/oauth2/authorize?client_id=<appId>&response_type=code');
POST https://api.dropboxapi.com/1/metadata/auto/ 401 (Unauthorized)
DropboxCloud @ DropboxCloud.js:8
(anonymous) @ MainWindowStandalone.js:45
DropboxCloud.js:10 {"error": "The given OAuth 2 access token doesn't exist or has expired."}
但是,如果我使用在 Dropbox 应用程序页面上生成的授权码,我可以成功访问该文件夹:
DropboxCloud.js:10 {"hash": "68a0fc8c0c5670ff10e8e98b7fefcde8", "thumb_exists": false, "bytes": 0, "path": "/", "is_dir": true, "icon": "folder", "root": "app_folder", "contents": [], "size": "0 bytes"}
我的代码:
var request = new XMLHttpRequest();
const url = 'https://api.dropboxapi.com/1/metadata/auto/';
request.open('post', url, true);
request.setRequestHeader('Authorization', 'Bearer ' + accessToken);
request.setRequestHeader('Content-Type', 'application/json');
request.send();
request.onload = () => {
console.log(request.response);
};
我想授予其他人使用代码生成页面的访问权限,以帮助我测试我的应用程序。我还需要什么才能让它发挥作用?
这里的问题是 "authorizations codes" 与 "access tokens" 不同,不能互换使用。
当您使用 OAuth 2 "token" 流程或通过 App Console 上应用程序页面上的 "Generate" 按钮检索令牌时,会为您提供一个实际的 Dropbox API OAuth 2 访问令牌。可用于进行 API 调用,例如 /1/metadata。
当您使用 OAuth 2 "code" 流程时,您从 /oauth2/authorize 返回的字符串只是一个授权代码。它本身不能用于进行 API 调用。这是一个临时代码,您可以使用 /oauth2/token.
交换访问令牌
(另外,注意Dropbox API v1,比如/1/metadata,是deprecated。)
我正在尝试从本地主机上的网页 运行 测试连接到 Dropbox 应用程序(在我的帐户上创建)。我选择生成授权代码而不是使用重定向。当我尝试访问应用程序文件夹的元数据时,代码页 (https://www.dropbox.com/1/oauth2/authorize_submit) 上生成和显示的任何代码似乎都会在控制台中产生错误:
window.open('https://www.dropbox.com/1/oauth2/authorize?client_id=<appId>&response_type=code');
POST https://api.dropboxapi.com/1/metadata/auto/ 401 (Unauthorized)
DropboxCloud @ DropboxCloud.js:8
(anonymous) @ MainWindowStandalone.js:45
DropboxCloud.js:10 {"error": "The given OAuth 2 access token doesn't exist or has expired."}
但是,如果我使用在 Dropbox 应用程序页面上生成的授权码,我可以成功访问该文件夹:
DropboxCloud.js:10 {"hash": "68a0fc8c0c5670ff10e8e98b7fefcde8", "thumb_exists": false, "bytes": 0, "path": "/", "is_dir": true, "icon": "folder", "root": "app_folder", "contents": [], "size": "0 bytes"}
我的代码:
var request = new XMLHttpRequest();
const url = 'https://api.dropboxapi.com/1/metadata/auto/';
request.open('post', url, true);
request.setRequestHeader('Authorization', 'Bearer ' + accessToken);
request.setRequestHeader('Content-Type', 'application/json');
request.send();
request.onload = () => {
console.log(request.response);
};
我想授予其他人使用代码生成页面的访问权限,以帮助我测试我的应用程序。我还需要什么才能让它发挥作用?
这里的问题是 "authorizations codes" 与 "access tokens" 不同,不能互换使用。
当您使用 OAuth 2 "token" 流程或通过 App Console 上应用程序页面上的 "Generate" 按钮检索令牌时,会为您提供一个实际的 Dropbox API OAuth 2 访问令牌。可用于进行 API 调用,例如 /1/metadata。
当您使用 OAuth 2 "code" 流程时,您从 /oauth2/authorize 返回的字符串只是一个授权代码。它本身不能用于进行 API 调用。这是一个临时代码,您可以使用 /oauth2/token.
交换访问令牌(另外,注意Dropbox API v1,比如/1/metadata,是deprecated。)