dcblogdev / laravel-microsoft-graph

Laravel package for Microsoft Graph API (Microsoft365)
https://dcblog.dev/docs/laravel-microsoft-graph
Other
122 stars 52 forks source link

Any way to get the photo using responseType = blob? #21

Closed fzhan closed 2 years ago

fzhan commented 2 years ago

Hi,

I'm trying to get the photo using:

MsGraph::get('me/photo/$value');

But the response is NULL, I've checked the other online documents, such request need to have a different responseType.

Any ideas?

dcblogdev commented 2 years ago

Yes, I've changed the inner works so when a binary response is detected its returned directly rather then trying to decode the response.

You can then pass the response into a base64 image:

$photo = MsGraph::get('me/photo/$value');
echo "<img src='data:image/png;base64,".base64_encode($photo)."'>";
jcfrazier6 commented 8 months ago

I am trying to the all users' data and combine their photos. Per the below, I am running the first call to get the user data. the second call is getting the user's photo based on id. All is combined, which works fine. My issue is that I can't get the photo to show onside the page table. I have tried using what you posted below but that isn't working. Any help is appreciated.

$Employees = MSGraph::get('users?$select=id,displayName,userPrincipalName');

$combinedResults = [];

foreach ($Employees['value'] as $Employee) { $userId = $Employee['id'];

// Retrieve employee photo
$Photos = MSGraph::get("users/{$userId}/photo/\$value");

// Combine the results
$combinedResults[] = [
    'id' => $userId,
    'displayName' => $Employee['displayName'],
    'userPrincipalName' => $Employee['userPrincipalName'],
    'photo' => $Photos, 
];

}

@foreach($combinedResults as $Employee)

{{ $Employee['id'] }} {{ $Employee['displayName'] }} {{ $Employee['userPrincipalName'] }} User Photo

@endforeach