2016-01-08 116 views
1

我試圖從O365使用Microsoft Graph API獲取用戶個人資料照片。當我使用以下API時,它只返回與配置文件圖片相關的元數據。從O365獲取用戶個人資料照片 - microsoft graph api

https://graph.microsoft.com/beta/me/photo

通過https://graph.microsoft.com/beta/me/photo/ $值返回亂碼對象,它沒有任何意義。但是,我相信這是與用戶配置文件相關的數據。需要幫助將這些數據提取到base64中。

+0

這應該是一個數據流 - jpeg圖像。你使用什麼平臺/語言? –

回答

1

返回的數據是圖像類型的二進制數據。如果您使用JavaScript檢索用戶照片,請在XMLHttpRequest中將照片數據作爲blob類型獲取,然後從響應中檢索blob URL。供您參考:

var request = new XMLHttpRequest; 
var photoUri=config.endpoints.graphApiUri + "/v1.0/me/photo/$value"; 
request.open("GET",photoUri); 
request.setRequestHeader("Authorization","Bearer "+token); 
request.responseType = "blob"; 
request.onload = function(){ 

if(request.readyState == 4 && request.status == 200){ 

var image = document.createElement("img"); 
var url = window.URL || window.webkitURL; 
var blobUrl = url.createObjectURL(request.response); 
image.src = blobUrl; 
    document.getElementById("UserShow").appendChild(image); 
} 

}; 
request.send(null); 
相關問題