我已经使用 NodeJS/Express 设置了一个服务器应用程序,并试图让以下脚本工作,以便它将 http-request 的返回值存储在一个变量中以供以后使用。
function checkIfVerified(req, res) {
var user_id = req.user.id
var options = {
method: 'GET',
url: 'https://MYDOMAIN/api/v2/users/' + user_id + '?fields=email_verified&include_fields=true',
headers:
{
authorization: 'Bearer ' + app.locals.token
},
body:
{
},
json: true
}
function check(callback) {
request(options, function (error, response, body) {
return callback(null, body)
})
}
var email_verified = check(function (err, data) {
if (!err) {
return data
}
})
console.log(email_verified)
return email_verified
}
由于某种原因,变量“email_verified”没有任何价值......
谢谢你的帮助!干杯菲利普