79632745

Date: 2025-05-21 20:59:47
Score: 1.5
Natty:
Report link

Welp. RTFM. https://learn.microsoft.com/en-us/graph/api/shares-get?view=graph-rest-1.0&tabs=http

async function getDriveItemBySharedLink(sharedLink) {
  // First, use base64 encode the URL.
  const base64 = Buffer.from(sharedLink).toString("base64");
  // Convert the base64 encoded result to unpadded base64url format by removing = characters from the end of the value, replacing / with _ and + with -.)
  const converted = base64
    .replace(/=/g, "")
    .replace(/\+/g, "-")
    .replace(/\//g, "_");
  // Append u! to be beginning of the string.
  const updatedLink = `u!${converted}`;
  const getDownloadURL = `https://graph.microsoft.com/v1.0/shares/${updatedLink}/driveItem`;

  const authResponse = await auth.getToken();
  const dirResponse = await axios.get(getDownloadURL, {
    headers: {
      Authorization: `Bearer ${authResponse.accessToken}`,
    },
  });

  return dirResponse.data;
}
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Dan Morgan