79232767

Date: 2024-11-28 06:22:54
Score: 1
Natty:
Report link

I was able to get the url from the same Microsoft graph API

POST /me/drive/items/{itemId}/createLink

Once done I manually added some query parameters which remains same in all embed urls (em=2&wdAr=1.7777777777777777). Hence this url I was able to use in the iframe tag in react.

try {
  const response = await fetch(
    `https://graph.microsoft.com/v1.0/me/drive/items/${fileId}/createLink`,
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ type: "embed" }),
    }
  );
  if (response.ok) {
    const result = response.json;
    const embed = result.link.webUrl + "?em=2&wdAr=1.7777777777777777"; //got the correct embed url
  }
} catch (error) {
  console.error("Error creating sharing link:", error);
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Filler text (0.5): 7777777777777777
  • Low reputation (1):
Posted by: akaparadox