【问题标题】:How to get working Dialog API of OfficeJS API with Outlook 2016 desktop client如何使用 Outlook 2016 桌面客户端使用 OfficeJS API 的对话框 API
【发布时间】:2016-12-21 09:20:54
【问题描述】:

我开发了一个使用 OfficeJS API 并希望在应用程序中实现 OAuth 的 Outlook 插件,也 API Documnetation 说 Outlook 2016(Desktop) 支持要求集 1.1、1.2、1.3 和 1.4,但在我的情况下,它保持沉默甚至不会引发错误。 在运行 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-js office-addins outlook-web-addins


    【解决方案1】:

    看起来Office.context 的成员ui 未定义或Office.js 未正确加载。尝试先查看这些:

    • Office.js javascript 是否加载正确?
    • Office.initialize 回调在你做某事之前是否设置好并执行?
    • 您的 Outlook Desktop 2016 版本是多少?

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

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

    【讨论】:

    • Office JS 加载正确,Office.initialize 回调也正确执行,因为所有其他操作都在正常工作。我在单击按钮时调用函数dialogTest()。我的办公桌面版本是:Word 2016 MSO (16.0.4266.1001) 我通过从微软官方下载页面下载的 ISO 安装了 Office Professional Plus 2016
    • var result = Office.context.requirements.isSetSupported('DialogAPI', '1.1'); 给予false
    • 我认为您的 Office 版本太旧并且没有带来包括dialogAPI 在内的最新更改(请参阅我的更新答案)。我认为您应该使用 Click To Run 安装以获取所有最新功能。
    • 是的,你是对的,更新了 Office 版本,它现在开始工作了。感谢您的 cmets :)
    • 谁能帮我解决这个问题? stackoverflow.com/questions/42950678/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-19
    相关资源
    最近更新 更多