我正在节点js中编写一个执行以下操作的程序。
我的节目如下。
function getUserDetailsFromAccessToken(session) {
var token = session.user.accessToken;
try {
// parse this and get user attributes
var decoded = jwt.decode(token);
getTheUserProfile(decoded.firstname, token, session);
} catch (err) {
console.log(err);
}
}
var hostUrl= "myUrlToGetResult";
function getTheUserProfile(nameFromSession, token, session) {
console.log("Incomung values " + nameFromSession);
console.log("Inside getUsersProfile Block");
var jsonToPass = {
"accesstoken": token,
"domain": "DomainName",
"lanid": nameFromSession
};
console.log("json to pass " + JSON.stringify(jsonToPass));
var options = {
uri: hostUrl+ "/api/admin/GetUserInfo",
method: "POST",
json: jsonToPass
};
request(options, function (error, resp, body) {
console.log("resp code is " + resp.statusCode);
if (!error && resp.statusCode == 200) {
if (body) {
console.log("Insode B1");
console.log(body.firstName);
} else {
console.log("I am unable to authenticate you. please disable the skill and re link your account");
}
} else {
console.log(error);
}
});
}
当我运行此程序时,我只能打印到console.log("json to pass " + JSON.stringify(jsonToPass));
,之后我无法从request()
块获得任何结果。
请让我知道我哪里出错了,我该怎么办呢。