我正在尝试将DialogAPI用于我的react Outlook加载项以获取图形API调用的访问令牌。我已经完成了打开对话框API的代码,并获取了代码,然后使用该代码检索访问令牌。但是,当我尝试关闭对话框时,抛出一个错误,提示未定义“ Office.context.ui.messageParent”。
Office.context.ui.displayDialogAsync(
"https://localhost:3000/assets/auth.html",
{ height: 30, width: 20 },
function(asyncResult) {
console.log("Dialog failed 1");
dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived, function(
_arg
) {
console.log("Dialog failed 2");
dialog.close();
});
}
);
代码
<script>
Office.initialize = function() {
showLogin();
Office.context.ui.messageParent("jsonMessage");
};
function showLogin() {
var ClientId = "a53cbaa8-7d4a-4739-8b1c-1f05ee2c545e";
var RedirectUrl =
"https://localhost:3000/wwwroot/redirect.html";
var url =
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize?" +
"client_id=" +
ClientId +
"&" +
"response_mode=query&" +
"response_type=code&" +
"scope=openid offline_access https://graph.microsoft.com/Mail.ReadWrite&" +
"redirect_uri=" +
RedirectUrl +
"&" +
"prompt=consent";
console.log("Get login url");
window.location.replace(url);
}
</script>