Dropbox list_folder api javascript 不工作
Dropbox list_folder api javascript not working
var xhr = new XMLHttpRequest();
xhr.responseType = 'String';
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = xhr.response;
console.log(response);
}
};
xhr.open('POST', 'https://api.dropboxapi.com/2/files/list_folder');
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
path: '/lol'
}));
xhr.send();
我无法弄清楚代码中似乎有什么问题。有帮助吗?
正在查看 list_folder 的文档 - 该端点是一个 RPC 端点:
These endpoints accept arguments as JSON in the request body and return results as JSON in the response body. RPC endpoints are on the api.dropboxapi.com domain.
Dropbox-API-Arg
header 似乎用于 Content-upload
和 Content-download
类型端点
我没有看到关于 /files/list_folder
端点所需的名为 Dropbox-API-Arg
的 header 的任何信息。试试像
xhr.open('POST', 'https://api.dropboxapi.com/2/files/list_folder');
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({path:"/lol"}));
var xhr = new XMLHttpRequest();
xhr.responseType = 'String';
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = xhr.response;
console.log(response);
}
};
xhr.open('POST', 'https://api.dropboxapi.com/2/files/list_folder');
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
path: '/lol'
}));
xhr.send();
我无法弄清楚代码中似乎有什么问题。有帮助吗?
正在查看 list_folder 的文档 - 该端点是一个 RPC 端点:
These endpoints accept arguments as JSON in the request body and return results as JSON in the response body. RPC endpoints are on the api.dropboxapi.com domain.
Dropbox-API-Arg
header 似乎用于 Content-upload
和 Content-download
类型端点
我没有看到关于 /files/list_folder
端点所需的名为 Dropbox-API-Arg
的 header 的任何信息。试试像
xhr.open('POST', 'https://api.dropboxapi.com/2/files/list_folder');
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({path:"/lol"}));