我发帖https://api.instagram.com
,但我不知道如何阅读回复。当我尝试console.log(response.body);
时,我得到undefined
这是我的代码:
var form = new FormData();
form.append('client_id','fc50049ba7df49b7b96535f892642366')
form.append('client_secret','6658e18d25e740e691c0cdcdd9adeabf')
form.append('grant_type','authorization_code')
form.append('redirect_uri','http://localhost:1992/oauth/ig')
form.append('code',req.query.code)
form.submit("https://api.instagram.com/oauth/access_token", (error, response) => {
console.log(`STATUS: ${response.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(response.headers)}`);
console.log(response.body)
var body = "";
response.setEncoding('utf8');
response.on('data', function(chunk) {
body += chunk;
});
response.on('end', function() {
console.log(body);
res.send(body);
});
});
答案 0 :(得分:0)
来自 response
的 form.submit()
类型是 IncomingMessage
,来自 http
。所以你可以这样做:
res.on('data', (chunk) => {
console.log(chunk) // this is your response body
})