2016-12-21 37 views
2

我開發了一個使用OfficeJS API並希望在應用內實現OAuth的Outlook加載項,也稱爲Outlook 2016(桌面)支持需求集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如何使用Outlook 2016桌面客戶端獲得OfficeJS API的對話API

我使用的是Microsoft Office專業增強版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(); 
      }); 
     }); 
    } 

回答

2

貌似的Office.contextui成員沒有定義或Office.js裝入不正確。請先試一下:

  • Office.js javascript加載是否正確?
  • Office.initialize回撥設置好並在你做某事之前執行?
  • 什麼是您的Outlook Desktop 2016版本?

編輯:與2016年6月微軟工程師討論(這是沒有官方的說法)。 dialogAPI支持的版本是Office Desktop for Windows Desktop 2016(版本16.0.6741.0000或更高版本)。這可能會改變。

  • 這是什麼一段代碼 var result = Office.context.requirements.isSetSupported('DialogAPI', '1.4');
+0

辦公室JS正確加載也Office.initialize回調適當地執行,因爲其他所有的操作都在地方工作的結果。我點擊一個按鈕來調用函數'dialogTest()'。我的辦公桌面版本是:** Word 2016 MSO(16.0.4266.1001)**我通過從Microsoft官方下載頁面下載的ISO安裝了** Office Professional Plus 2016 **。 – Hitendra

+0

'var result = Office.context.requirements.isSetSupported('DialogAPI','1.1');'given'false' – Hitendra

+0

我認爲你的Office版本太舊了,並沒有帶來最新的變化,包括'dialogAPI'(看到我更新的答案)。我想你應該使用Click To Run進行安裝以獲得所有最新功能。 –