第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 python 在 Microsoft Graph 中顯示用戶的圖像

如何使用 python 在 Microsoft Graph 中顯示用戶的圖像

守候你守候我 2022-10-11 10:06:14
我嘗試使用 GET https://graph.microsoft.com/v1.0/me/photo/$value來獲取用戶的圖像/照片,但它只返回 HTTP 200 狀態(tài)代碼。如何獲取二進制數(shù)據(jù)?我也嘗試過使用content.property ,如在類似帖子中建議的那樣,但 get a.format不是字典的屬性。@app.route("/photo")def get_photo():    token = _get_token_from_cache(app_config.SCOPE)    if not token:        return redirect(url_for("login"))    photo = requests.get(app_config.PHOTO_ENDPOINT,              headers={'Authorization': 'Bearer ' + token['access_token']})    print(photo.status_code)    return photo
查看完整描述

3 回答

?
慕哥9229398

TA貢獻1877條經(jīng)驗 獲得超6個贊

獲取個人資料照片,并可選擇保存本地副本。返回原始照片數(shù)據(jù)、HTTP 狀態(tài)代碼、內(nèi)容類型和保存的文件名的元組。請參閱此示例。

def profile_photo(session, *, user_id='me', save_as=None):

    """Get profile photo, and optionally save a local copy.

    session = requests.Session() instance with Graph access token

    user_id = Graph id value for the user, or 'me' (default) for current user

    save_as = optional filename to save the photo locally. Should not include an

              extension - the extension is determined by photo's content type.

    Returns a tuple of the photo (raw data), HTTP status code, content type, saved filename.

    """


    endpoint = 'me/photo/$value' if user_id == 'me' else f'users/{user_id}/$value'

    photo_response = session.get(api_endpoint(endpoint),

                                 stream=True)

    photo_status_code = photo_response.status_code

    if photo_response.ok:

        photo = photo_response.raw.read()

        # note we remove /$value from endpoint to get metadata endpoint

        metadata_response = session.get(api_endpoint(endpoint[:-7]))

        content_type = metadata_response.json().get('@odata.mediaContentType', '')

    else:

        photo = ''

        content_type = ''


    if photo and save_as:

        extension = content_type.split('/')[1]

        filename = save_as + '.' + extension

        with open(filename, 'wb') as fhandle:

            fhandle.write(photo)

    else:

        filename = ''


    return (photo, photo_status_code, content_type, filename)


查看完整回答
反對 回復 2022-10-11
?
30秒到達戰(zhàn)場

TA貢獻1828條經(jīng)驗 獲得超6個贊

如果您想在網(wǎng)頁上顯示生成的圖像,則基于原始問題的代碼的替代方法。


from base64 import b64encode


@app.route("/photo")

def get_photo():

    token = _get_token_from_cache(app_config.SCOPE)

    if not token:

        return redirect(url_for("login"))

    response = requests.get(

        app_config.PHOTO_ENDPOINT,  

        headers={'Authorization': 'Bearer ' + token['access_token']}

    )

    content_type = response.raw.getheader('Content-Type')

    return render_template('index.html',

                           photo_data=b64encode(response.content),

                           photo_content_type=content_type)

然后在index.html模板中,您可以像這樣顯示照片:


<html>

  <body>

    <img src="data:{{ photo_content_type }};base64,{{ photo_data }}" />

  </body>

</html>


查看完整回答
反對 回復 2022-10-11
?
夢里花落0921

TA貢獻1772條經(jīng)驗 獲得超6個贊

Call Api: - 


    Axios.get('https://graph.microsoft.com/v1.0/me/photo/$value', {

                  headers: { 'Authorization': 'Bearer '+AccessToken },

                  responseType: 'blob'

                }).then(o => {

                  const url = window.URL || window.webkitURL;

                  const blobUrl = url.createObjectURL(o.data);

                  

                    self.setState({ imageUrl: blobUrl });

                })


JSX: -

 <img alt="image" src={this.state.imageUrl} />


查看完整回答
反對 回復 2022-10-11
  • 3 回答
  • 0 關注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號