Last active
May 21, 2023 16:51
-
-
Save nelsondev19/7e945be76502e1bd50e9af38418bf74f to your computer and use it in GitHub Desktop.
Get profile image from Microsoft with TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getImageProfileMicrosoft = (accessToken: string) => { | |
const headers = new Headers(); | |
headers.append("Authorization", `Bearer ${accessToken}`); | |
fetch("https://graph.microsoft.com/v1.0/me/photo/$value", { | |
method: "GET", | |
headers: headers, | |
}) | |
.then((response) => { | |
if (!response.ok) { | |
throw new Error("Network response was not ok"); | |
} | |
return response.blob(); | |
}) | |
.then((blob) => { | |
const url = URL.createObjectURL(blob); | |
const image = document.getElementById("profileImage"); | |
image.src = url; | |
}) | |
.catch((error) => console.error("There was a problem:", error)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment