如何使用 Outlook 2016 桌面客户端使用 OfficeJS API 的对话框 API

How to get working Dialog API of OfficeJS API with Outlook 2016 desktop client

我开发了一个使用 OfficeJS API 的 outlook 插件,并且想在应用程序中实现 OAuth,也 API Documnetation 表示 Outlook 2016(桌面版)支持要求集 1.1、1.2、1.3 和 1.4,但在我的情况下它保持沉默甚至不抛出错误。 在 运行ning 工作时 dialog api sample for word add-in 我正在 JavaScript 运行-时间错误: Unable to get property 'displayDialogAsync' of undefined or null reference.

我正在使用 Microsoft Office Professional Plus 2016。

我编写的用于启动对话框的代码如下:

dialogTest() {
        const url = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=....";
        Office.context.ui.displayDialogAsync(url, { width: 15, height: 27, requireHTTPS: true }, function (asyncResult) {
            if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
                // TODO: Handle error.
                return;
            }

            // Get the dialog and register event handlers.
            var dialog = asyncResult.value;
            dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogMessageReceived, function (asyncResult) {
                if (asyncResult.type !== Microsoft.Office.WebExtension.EventType.DialogMessageReceived) {
                    // TODO: Handle unknown message.
                    return;
                }

                // Parse the message.
                var data = JSON.parse(asyncResult.message);
                console.log('Hello #Office365Dev', data.name);

                // TODO: Do something with the data.

                // We got our data, time to close the dialog.
                dialog.close();
            });
        });
    }

看起来 Office.contextui 成员未定义或 Office.js 未正确加载。尝试先复习这些:

  • Office.js javascript 加载正确吗?
  • Office.initialize 是否在您做某事之前正确设置并执行了回调?
  • 您的 Outlook 桌面版 2016 是什么版本?

编辑: 2016 年 6 月与 Microsoft 工程师讨论(这不是官方声明)。 dialogAPI 支持的版本是 Office for Windows Desktop 2016(版本 16.0.6741.0000 或更高版本)。这可能会改变。

  • 这段代码的结果是什么 var result = Office.context.requirements.isSetSupported('DialogAPI', '1.4');