【发布时间】:2015-12-10 21:04:57
【问题描述】:
我正在编写一个 node.js cli 来学习 HTTP 请求。我想下载一个文件并将其保存到本地文件夹。我遇到的问题是从 Dropbox 获取文件。我已经阅读他们的 API 大约一天了,但仍然不明白如何浏览它。这是我的代码:
var https = require('https'),
clc = require('cli-color'),
options = {
protocol: 'https:',
hostname: 'www.dropbox.com',
path: '/1/oauth2/authorize?client_id=<<my-id>>response_type=code',
method: 'GET'
},
token;
var req = https.get(options, function (res) {
if (res) {
console.log(clc.green('success'));
}
res.on('data', function (data) {
console.log(data);
})
});
我正在关注来自 Dropbox API 的 code OAuth 授权流程。当我运行index.js 文件时,它返回的数据是这样的:
<Buffer 6f 6d 70 6f 6e 65 6e 74 73 5f 5f 69 6e 70 75 74 2e 54 65 78 74 49 6e 70 75 74 2c 20 5b 5d 29 3b 20 7d 28 6d 6f 64 75 6c 65 73 5f 5f 63 6c 65 61 6e 5f ... >
这是授权码吗?如果没有,我该怎么做才能得到它并存储它?
【问题讨论】:
标签: javascript node.js http https