无法阅读属性&display; displayDialogAsync'未定义的,microsoft / office-js-helpers

时间:2017-09-27 19:43:58

标签: javascript office-js outlook-web-addins

按照https://github.com/OfficeDev/office-js-helpers

中的示例

这是我的代码:

Office.initialize = () => {
    if (OfficeHelpers.Authenticator.isAuthDialog()) return;

    var authenticator = new OfficeHelpers.Authenticator();
    authenticator.endpoints.add("TW", {
        provider: 'TW',
        clientId: "twplugin",
        baseUrl: "https://auth.tw.io",
        authorizeUrl: "https://auth.tw.io/connect/authorize",
        redirectUrl: "https://localhost:3000/index.html",
        state: true,
        responseType: "id_token token",
        scope: "openid profile twapi3 allow-full-access"
    });

    authenticator
        .authenticate('TW')
        .then(function (token) {
            console.log('Success: ' + token);
        })
        .catch(OfficeHelpers.Utilities.log);
};

尝试获取登录屏幕时收到以下错误消息。

VM1930:175 TypeError: Cannot read property 'displayDialogAsync' of undefined
VM1930:187 Stack Trace
VM1930:188 TypeError: Cannot read property 'displayDialogAsync' of undefined
    at eval (eval at ../node_modules/@microsoft/office-js-helpers/dist/helpers/dialog.js (app.65ef65e66b97ddb4ec4f.js:847), <anonymous>:68:31)
    at new Promise (<anonymous>)
    at Dialog._addinDialog (eval at ../node_modules/@microsoft/office-js-helpers/dist/helpers/dialog.js (app.65ef65e66b97ddb4ec4f.js:847), <anonymous>:67:16)
    at Dialog.get [as result] (eval at ../node_modules/@microsoft/office-js-helpers/dist/helpers/dialog.js (app.65ef65e66b97ddb4ec4f.js:847), <anonymous>:58:81)
    at Authenticator.eval (eval at ../node_modules/@microsoft/office-js-helpers/dist/authentication/authenticator.js (app.65ef65e66b97ddb4ec4f.js:799), <anonymous>:193:101)
    at step (eval at ../node_modules/@microsoft/office-js-helpers/dist/authentication/authenticator.js (app.65ef65e66b97ddb4ec4f.js:799), <anonymous>:43:23)
    at Object.eval [as next] (eval at ../node_modules/@microsoft/office-js-helpers/dist/authentication/authenticator.js (app.65ef65e66b97ddb4ec4f.js:799), <anonymous>:24:53)
    at eval (eval at ../node_modules/@microsoft/office-js-helpers/dist/authentication/authenticator.js (app.65ef65e66b97ddb4ec4f.js:799), <anonymous>:18:71)
    at new Promise (<anonymous>)
    at __awaiter (eval at ../node_modules/@microsoft/office-js-helpers/dist/authentication/authenticator.js (app.65ef65e66b97ddb4ec4f.js:799), <anonymous>:14:12)

看来我没有正确初始化,但不确定是什么。我知道我的授权设置是正确的,我有一个简单的应用程序做同样的事情。

我也试过这段代码:

Office.initialize = () => {
    Office.context.ui.displayDialogAsync(
        'https://dev.office.com/docs/add-ins/develop/dialog-api-in-office-add-ins');
};

收到以下错误:

main.tsx?5918:18 Uncaught TypeError: 
Cannot read property 'displayDialogAsync' of undefined
    at Object.Office.initialize (eval at ./main.tsx (app.0b7207f9d2d5e61b003a.js:4544), <anonymous>:17:27)
    at OSF_InitializationHelper$prepareRightBeforeWebExtensionInitialize [as
prepareRightBeforeWebExtensionInitialize] (o15apptofilemappingtable.debug.js:7191)
    at office.debug.js:750
    at validateFunction (office.debug.js:256)

0 个答案:

没有答案