小编soj*_*ung的帖子

如何使用 Microsoft Graph API 获取用户的照片(个人资料)?

当发出 GET( https://graph.microsoft.com/v1.0/users/ {{user_id}} /photo/$value) 请求时,响应数据将写入与图像相同的字符

图片.

转换为base64后,我尝试了blob格式,但图片没有出现。

路由器.js

router.get('/photo/:id',function (req,res) {
  auth.getAccessToken().then(function (token){
   let userId = req.params.id;
   graph.getUserPhotoData(token, userId).then(function (result) {
      res.json(result);
    }).catch(function (e) { console.log(e) })
  });
});
Run Code Online (Sandbox Code Playgroud)

图.js

function getUserPhoto(token, userId){
  return axios({
    method : 'get',
    url : 'https://graph.microsoft.com/v1.0/users/'+{{user_id}}+'/photo/$value',
    headers: {
      'Authorization':token,
      // 'Content-Type': 'image/jpeg',
    },
    responseType : 'blob'
  })
}


async function getUserPhotoData(token,userId) {
  try{
    let userPhoto = getUserPhoto(token,userId);
    let p = userPhoto.data;
    // let photo = new Buffer(userPhoto.data).toString('base64');
    return p; //...013O?\u0011?e????|??>?4+?y??\u0017?"Y...
  }catch (e) { console.log(e);} …
Run Code Online (Sandbox Code Playgroud)

javascript microsoft-graph-api

3
推荐指数
2
解决办法
6551
查看次数

标签 统计

javascript ×1

microsoft-graph-api ×1