1
我想通過Microsoft Graph從我的Microsoft帳戶中查看我的聯繫人。從https://github.com/microsoftgraph/nodejs-connect-rest-sample 代碼我在utils的/ graphHelper.jsMicrosoft Graph獲得基本聯繫人(Node.js)
function getUserContact(accessToken, callback) {
request
.get('https://graph.microsoft.com/v1.0/me/contacts')
.set('Authorization', 'Bearer ' + accessToken)
.end((err, res) => {
callback(err, res);
});
}
添加getUserContact功能並且這添加至底部的graphHelper.js文件
exports.getUserContact = getUserContact;
和在文件夾路徑 - > index.js從
router.get('/token',
passport.authenticate('azuread-openidconnect', { failureRedirect: '/' }),
(req, res) => {
graphHelper.getUserData(req.user.accessToken, (err, user) => {
if (!err) {
req.user.profile.displayName = user.body.displayName;
req.user.profile.emails = [{ address: user.body.mail || user.body.userPrincipalName }];
renderSendMail(req, res);
} else {
renderError(err, res);
}
});
});
被修改,以
router.get('/token',
passport.authenticate('azuread-openidconnect', { failureRedirect: '/' }),
(req, res) => {
graphHelper.getUserContact(req.user.accessToken, (err, user) => {
if (!err) {
req.user.profile.displayName = user.body;
//req.user.profile.emails = [{ address: user.body.mail || user.body.userPrincipalName }];
renderSendMail(req, res);
} else {
renderError(err, res);
}
});
});
(修改添加getUserContact在45-48 Line在index.js文件)
,然後在項目目錄
任何解決方案?
三江源
更新:在config.js文件11:22 15/6/2017 更新(添加contact.read)
scope: ['User.Read', 'Mail.Send', 'Files.ReadWrite','Contacts.Read']
感謝您的幫助,但它仍然無法正常工作我剛剛更新'Contacts.Read'以在config.js中進行範圍。 範圍:['User.Read','Mail.Send','Files.ReadWrite','Contacts.Read'] 但在認證頁面失敗後,再次失敗 – Joey
我剛更新我的問題在上面的主題 – Joey