【发布时间】:2017-01-04 19:18:52
【问题描述】:
我正在尝试创建一个 Azure EasyAPI 以从我的应用程序中的身份提供者 (microsoft) 获取一些用户信息。但是,我从网上找到的所有示例中都遇到了错误,而且我在 stackoverflow 上找到的答案都没有帮助。
错误:
Azure Log:
: Application has thrown an uncaught exception and is terminated:
SyntaxError: Unexpected end of input
at Object.parse (native)
at IncomingMessage.<anonymous> (D:\home\site\wwwroot\node_modules\azure-mobile-apps\src\auth\getIdentity.js:35:55)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:903:12)
at doNTCallback2 (node.js:439:9)
at process._tickCallback (node.js:353:17)
代码:
module.exports = {
"get": function (request, response, next) {
request.azureMobile.user.getIdentity('microsoftaccount').then(function (data) {
var accessToken = data.microsoftaccount.access_token;
var url = 'https://apis.live.net/v5.0/me/?method=GET&access_token=' + accessToken;
var requestCallback = function (err, resp, body) {
if (err || resp.statusCode !== 200) {
console.error('Error sending data to the provider: ', err);
response.send(statusCodes.INTERNAL_SERVER_ERROR, body);
} else {
try {
var userData = JSON.parse(body);
response.send(200, userData);
} catch (ex) {
console.error('Error parsing response from the provider API: ', ex);
response.send(statusCodes.INTERNAL_SERVER_ERROR, ex);
}
}
var req = require('request');
var reqOptions = {
uri: url,
headers: { Accept: "application/json" }
};
req(reqOptions, requestCallback);
};
}).catch(function (error) {
response.status(500).send(JSON.stringify(error));
});
//...
}};
感谢您的帮助。
【问题讨论】:
-
也许这个答案会对你有所帮助:stackoverflow.com/questions/35878102/…
-
这改变了错误——现在,在我的 c# 代码中,当我等待 API 调用时,它需要很长时间并且最终超时。在我的 Azure 输出中,我得到“愚蠢:GetIdentity Request: hostname=vflash.azurewebsites.net, port=443, path=/.auth/me?provider=[object Object], method=GET, + a very long string
标签: node.js azure azure-mobile-services