我想對GET操作發出POST請求。使用ExpressJS發出發佈請求
一切正常,但在帖子後我看不到「TOKEN」,我不明白爲什麼。
var request = require('request');
exports.getToken = function(req, res){
var postData = {
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
grant_type: 'authorization_code',
redirect_uri: REDIRECT_URI,
code: CODE
}
request.post({
uri:"https://api.instagram.com/oauth/access_token",
form: postData,
followRedirect: true,
maxRedirects: 10
},function(err,res,body){
var data = JSON.parse(body);
TOKEN = data.access_token;
});
console.log(TOKEN);
res.render('index', {title: '*****'});
}
你的問題是不是expressjs,也沒有特別的NodeJS。你的困惑是在javascript中的異步執行工作:http://stackoverflow.com/questions/7104474/how-does-asynchronous-javascript-execution-happen-and-when-not-to-use-return-st –
有一些閱讀材料爲你在這裏學習:http://stackoverflow.com/a/9355795/774086 –