我試圖創建Azure EasyAPI以從我的應用程序中的身份提供商(Microsoft)獲取某些用戶信息。然而,我在網上找到的所有例子都出現錯誤,而且我在stackoverflow上找到的答案都沒有幫助。從身份提供商和Azure EasyAPI獲取用戶信息
錯誤:
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));
});
//...
}};
感謝您的幫助。
也許這個答案將幫助您:http://stackoverflow.com/questions/35878102/get-facebook-auth-token-from-azure-easy-api –
這改變了錯誤 - 現在,在我的C#代碼,當我等待API調用時,它需要很長時間並最終超時。在我的Azure輸出中,我得到「愚蠢:GetIdentity Request:hostname = vflash.azurewebsites.net,port = 443,path = /。auth/me?provider = [object Object],method = GET,+一個非常長的字符串 – user3007447