2017-06-14 71 views
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文件)

,然后在项目目录

NPM启动登录过程后的结果是enter image description here

任何解决方案?

三江源

更新:在config.js文件11:22 15/6/2017 更新(添加contact.read)

scope: ['User.Read', 'Mail.Send', 'Files.ReadWrite','Contacts.Read'] 

但经过认证页面再次失败enter image description here

enter image description here

回答

2

您没有访问联系人所需的范围。您需要将Contacts.Read添加到config.js中的scope值。

+0

感谢您的帮助,但它仍然无法正常工作我刚刚更新'Contacts.Read'以在config.js中进行范围。 范围:['User.Read','Mail.Send','Files.ReadWrite','Contacts.Read'] 但在认证页面失败后,再次失败 – Joey

+0

我刚更新我的问题在上面的主题 – Joey

相关问题