<bdo id='5cYqU'></bdo><ul id='5cYqU'></ul>
<i id='5cYqU'><tr id='5cYqU'><dt id='5cYqU'><q id='5cYqU'><span id='5cYqU'><b id='5cYqU'><form id='5cYqU'><ins id='5cYqU'></ins><ul id='5cYqU'></ul><sub id='5cYqU'></sub></form><legend id='5cYqU'></legend><bdo id='5cYqU'><pre id='5cYqU'><center id='5cYqU'></center></pre></bdo></b><th id='5cYqU'></th></span></q></dt></tr></i><div id='5cYqU'><tfoot id='5cYqU'></tfoot><dl id='5cYqU'><fieldset id='5cYqU'></fieldset></dl></div>

    <legend id='5cYqU'><style id='5cYqU'><dir id='5cYqU'><q id='5cYqU'></q></dir></style></legend>

    <small id='5cYqU'></small><noframes id='5cYqU'>

      <tfoot id='5cYqU'></tfoot>

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

        How to get user#39;s photo(profile) using Microsoft Graph API?(如何使用 Microsoft Graph API 获取用户的照片(个人资料)?)
        <i id='Pi0bp'><tr id='Pi0bp'><dt id='Pi0bp'><q id='Pi0bp'><span id='Pi0bp'><b id='Pi0bp'><form id='Pi0bp'><ins id='Pi0bp'></ins><ul id='Pi0bp'></ul><sub id='Pi0bp'></sub></form><legend id='Pi0bp'></legend><bdo id='Pi0bp'><pre id='Pi0bp'><center id='Pi0bp'></center></pre></bdo></b><th id='Pi0bp'></th></span></q></dt></tr></i><div id='Pi0bp'><tfoot id='Pi0bp'></tfoot><dl id='Pi0bp'><fieldset id='Pi0bp'></fieldset></dl></div>

          <bdo id='Pi0bp'></bdo><ul id='Pi0bp'></ul>

                  <small id='Pi0bp'></small><noframes id='Pi0bp'>

                  <legend id='Pi0bp'><style id='Pi0bp'><dir id='Pi0bp'><q id='Pi0bp'></q></dir></style></legend>
                  <tfoot id='Pi0bp'></tfoot>
                    <tbody id='Pi0bp'></tbody>
                1. 本文介绍了如何使用 Microsoft Graph API 获取用户的照片(个人资料)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当一个 GET(.

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

                  router.js

                  router.get('/photo/:id',function (req,res) {auth.getAccessToken().then(function (token){让 userId = req.params.id;graph.getUserPhotoData(token, userId).then(function (result) {res.json(结果);}).catch(函数 (e) { console.log(e) })});});

                  graph.js

                  function getUserPhoto(token, userId){返回 axios({方法:'get',网址:'https://graph.microsoft.com/v1.0/users/'+{{user_id}}+'/photo/$value',标题:{'授权':令牌,//'内容类型': '图片/jpeg',},响应类型:'blob'})}异步函数 getUserPhotoData(token,userId) {尝试{让 userPhoto = getUserPhoto(token,userId);让 p = userPhoto.data;//让 photo = new Buffer(userPhoto.data).toString('base64');返回 p;//...013Ou0011 e    |  > 4+ y  u0017 "Y...}catch (e) { console.log(e);}}

                  index.js

                  $.get('/photo/'+userId, function(response) {让二进制数据 = [];binaryData.push(响应);const blobUrl = window.URL.createObjectURL(new Blob(binaryData, {type: "image/jpeg"}));document.getElementById('user-img').setAttribute("src", blobUrl );});

                  解决方案

                  新缓冲区已被弃用.请使用 Buffer.from(response.data, 'binary').toString('base64');

                  对我有用

                  const graphEndpoint = "https://graph.microsoft.com/v1.0/me/photo/$value";const response = await axios(graphEndpoint, { headers: { Authorization: `Bearer ${token}` }, responseType: 'arraybuffer' });const avatar = new Buffer(response.data, 'binary').toString('base64');

                  When a GET(https://graph.microsoft.com/v1.0/users/ {{user_id}} /photo/$value) request is made, the response data will be written with the same characters as image

                  .

                  After converting to base64, I tried blob format but the picture does not appear.

                  router.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) })
                    });
                  });
                  

                  graph.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; //...013Ou0011e|>4+yu0017"Y...
                    }catch (e) { console.log(e);}
                  }
                  

                  index.js

                  $.get('/photo/'+userId, function(response) {
                    let binaryData = [];
                    binaryData.push(response);  
                    const blobUrl = window.URL.createObjectURL(new Blob(binaryData, {type: "image/jpeg"}));
                    document.getElementById('user-img').setAttribute("src", blobUrl );
                  });
                  

                  解决方案

                  Edit: new Buffer is deprected. Please use Buffer.from(response.data, 'binary').toString('base64');

                  it works for me

                  const graphEndpoint = "https://graph.microsoft.com/v1.0/me/photo/$value";
                  
                  const response = await axios(graphEndpoint, { headers: { Authorization: `Bearer ${token}` }, responseType: 'arraybuffer' });
                  const avatar = new Buffer(response.data, 'binary').toString('base64');
                  

                  这篇关于如何使用 Microsoft Graph API 获取用户的照片(个人资料)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                  Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                  JavaScript radio button confirmation(JavaScript 单选按钮确认)
                  How can I automatically select specific radio buttons with Greasemonkey?(如何使用 Greasemonkey 自动选择特定的单选按钮?)
                  AngularJs. Is it possible to deselect HTML “radio” input by click?(AngularJs.是否可以通过单击取消选择 HTML“收音机输入?)
                  Checking Value of Radio Button Group via JavaScript?(通过 JavaScript 检查单选按钮组的值?)
                  <legend id='3ExQf'><style id='3ExQf'><dir id='3ExQf'><q id='3ExQf'></q></dir></style></legend>

                  <small id='3ExQf'></small><noframes id='3ExQf'>

                  <tfoot id='3ExQf'></tfoot>
                  • <bdo id='3ExQf'></bdo><ul id='3ExQf'></ul>

                          <tbody id='3ExQf'></tbody>
                        • <i id='3ExQf'><tr id='3ExQf'><dt id='3ExQf'><q id='3ExQf'><span id='3ExQf'><b id='3ExQf'><form id='3ExQf'><ins id='3ExQf'></ins><ul id='3ExQf'></ul><sub id='3ExQf'></sub></form><legend id='3ExQf'></legend><bdo id='3ExQf'><pre id='3ExQf'><center id='3ExQf'></center></pre></bdo></b><th id='3ExQf'></th></span></q></dt></tr></i><div id='3ExQf'><tfoot id='3ExQf'></tfoot><dl id='3ExQf'><fieldset id='3ExQf'></fieldset></dl></div>