我正在使用 Outlook 添加 REST 调用来获取附件详细信息。但我收到一条错误消息:
{ “错误”: { "code": "RequestBroker--ParseUri", "message": "找不到段 'Q7GceiTKAvvXBwAtYompjmwrRqF359uQTkd1AAAAAAEJAAAtYompjmwrRqF359uQTkd1AAAHjsV0AAA=' 的资源。" } }
这是我的代码:
const encodedItemId = encodeURIComponent(Office.context.mailbox.item.itemId);
Office.context.mailbox.getCallbackTokenAsync({ isRest: true }, async function (result) {
if (result.status === Office.AsyncResultStatus.Succeeded) {
const callbackToken = result.value;
// Construct the URL to download attachment content
const attachmentUrl = 'https://outlook.office.com/api/v2.0/me/messages/' + encodedItemId+ "/attachments";
const headers = { Authorization: `Bearer ${callbackToken}` };
// Fetch attachment content
fetch(attachmentUrl, { headers })
.then(response => response.arrayBuffer())
.then(arrayBuffer => {
const attachmentName = attachment.name;
const base64Data = arrayBufferToBase64(arrayBuffer);
})
.catch(error => {
console.log("Failed to fetch attachment content:", error);
});
我还尝试了其他变体来构造网址,例如
常量附件Url =
${Office.context.mailbox.restUrl}/v2.0/me/messages/${item.itemId}/attachments/${attachmentId}/$value
;
我做错了什么?
您应该使用 RestID 而不是 EWSID,EWSID 是基于 64 位但不安全的 URL。