首页 > 解决方案 > 运行 Outlook COM 加载项(在 Windows 上的本机 Outlook 中)时,如何使用 Office.js API 获取委派日历的用户电子邮件?

问题描述

我正在开发一个 Outlook Web 插件并在 Windows 上的本机 Outlook 2019 中运行它。我的同事将他的日历委托给我,我可以访问他的日历,并且可以在共享日历的约会中运行我的网络插件。我正在使用 F12 开发人员工具查看控制台日志。所以,对我来说主要问题 - 获取共享日历的用户电子邮件。我试图得到Office.context.mailbox.item.organizer,但在 F12 DevTools 的控制台中我看到了undefined。当我尝试进入Office.context.mailbox.itemF12 Devtools 的控制台时,我看到[object] { }但我不知道如何查看所有对象属性。

manifest.xml我的加载项中,我添加了<SupportsSharedFolders>true</SupportsSharedFolders>,但它对我没有帮助(我认为只有当我在功能区中看不到我的加载项时才需要它,但我已经在没有此参数行的情况下看到了它)。

我还尝试将权限manifest.xml从“ReadWriteItem”更改为“ReadWriteMailbox” - 没有更改。

我查看了官方的 Microsoft 文档,在那里我读到我可以使用我调用的参数(链接到官方文档)调用Office.context.mailbox.item.saveAsync并作为回调函数传递,并且调用没有问题(除了我无法访问和可以的字段)由于 F12 Devtools,t 实际上看到控制台中有哪些字段),但在 F12 Devtools 的控制台中我看到了更多。如果调用此方法,我将执行以下操作:asyncResult0Office.context.mailbox.getCallbackTokenAsyncsaveAsyncasyncResult0.valueasyncResult0Object doesn't support property or method 'getCallbackTokenAsync', TypeError: Object doesn't support property or method 'getCallbackTokenAsync'

Office.context.mailbox.item.saveAsync(function (asyncResult0) {
  Office.context.mailbox.getCallbackTokenAsync({
      isRest: true
    },
    function (asyncResult) {
      if (asyncResult.status === Office.AsyncResultStatus.Succeeded && asyncResult.value !== "") {
        Office.context.mailbox.item.getSharedPropertiesAsync({
            // Pass auth token along.
            asyncContext: asyncResult.value
          },
          function (asyncResult1) {
            const sharedProperties = asyncResult1.value; // may be it contains shared calendar user email
            // some operations...
          }
        );
      }
    }
  );
});

重要细节:

  1. manifest.xml
  1. 我在共享日历中创建了一份约会草稿,并尝试了该草稿中上述所有内容。

  2. 我不知道如何更正确地调试 COM 插件(基于 Web 版本),现在我只知道 F12 Devtools。

  3. 我不知道它是否重要,但以防万一我在 Office 365 中运行我的加载项时写下(仅在我的日历的约会中,因为加载项没有<SupportsSharedFolders>true</SupportsSharedFolders>在 Office 365 中安装,没有它我可以'在共享日历中看不到加载项)我可以Office.context.mailbox.item在控制台中看到对象的所有属性。Office.context.mailbox.item.organizer返回带有方法的对象getAsync,如果我调用该方法(并使用参数作为回调函数传递result),我会得到result:({ status: "succeeded", value: { displayName: "...", emailAddress: "..." } }在这种情况下,当然是我的用户的数据)。而且我还能够获得asyncResult0传递给的回调saveAsync,以及asyncResult传递给的回调getCallbackTokenAsync。但是getSharedPropertiesAsync在控制台中调用时,我看到“Office.context.mailbox.item.getSharedPropertiesAsync 不是函数”。

  4. 在本机 Outlook 加载项中,使用Office = window.external对象作为 Office JS API 点。

  5. Office.context.mailbox.diagnostics.hostVersion在控制台显示:16.0.0.10368

请帮帮我。我不知道如何在 Appointment with Office.js API 中获取共享日历的用户电子邮件。我会很高兴任何线索。

此致!

标签: outlookoffice-jsoutlook-addinoffice-addinsoutlook-web-addins

解决方案


在共享日历/文件夹中,您只能通过调用Office.context.mailbox.item.getSharedPropertiesAsync获取所有者的电子邮件地址。在您自己的日历/文件夹(非共享)中,该getSharedPropertiesAsyncAPI 不存在,因为您可以简单地调用Office.context.mailbox.item.organizer以获取约会/会议所有者的电子邮件地址。


推荐阅读