conversationId - 值不能为NULL

时间:2017-06-01 11:45:47

标签: javascript microsoft-graph office-js office-addins

在Word-addin中,我试图在ADAL和microsoft.graph的帮助下从AAD获取数据。这是代码:

来自app.js

var app = (function () {
"use strict";

window.config = {
instance: 'https://login.microsoftonline.com/',
tenant: '<TENANT>',
clientId: '<CLIENTID>',
redirectUri: '<THE-APP-ADDRESS>',
postLogoutRedirectUri: window.location.origin,
endpoints: {
     officeGraph: 'https://graph.microsoft.com',
},
callback: userSignedIn,
popUp: true,
cacheLocation: 'localStorage'

};

function signIn() {
   authContext.login();
}

function userSignedIn(err, token) {
  console.log('userSignedIn called');
//   showWelcomeMessage();
  if (!err) {
      console.log("token: " + token);
      showWelcomeMessage();
  }
  else {
      console.error("error: " + err);
  }
 }

 function showWelcomeMessage() {
  var authContext = new AuthenticationContext(config);

    var $userDisplay = $(".app-user");
    var $signInButton = $(".app-login");
    var $signOutButton = $(".app-logout");

    // Check For & Handle Redirect From AAD After Login
    var isCallback = authContext.isCallback(window.location.hash);
    authContext.handleWindowCallback();

    if (isCallback && !authContext.getLoginError()) {
        window.location = authContext._getItem(authContext.CONSTANTS.STORAGE.LOGIN_REQUEST);
    }

和main.js

 function getDataFromSelection() {
    var baseEndpoint = 'https://graph.microsoft.com';
    var authContext = new AuthenticationContext(config);

    Office.context.document.getSelectedDataAsync(Office.CoercionType.Text,
        function (asyncResult) {
            if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {

                authContext.acquireToken(baseEndpoint, function (error, token) {
                    if (error || !token) {
                        app.showNotification("Ingen token: ", "Du får logga in igen." + error); // + error
                    }
                    //var email = authContext._user.userName;
                    var url = "https://graph.microsoft.com/v1.0/" + config.tenant + "/me";

                    var html = "<ul>";
                    $.ajax({
                        beforeSend: function (request) {
                            request.setRequestHeader("Accept", "application/json");
                        },
                        type: "GET",
                        url: url,
                        dataType: "json",
                        headers: {
                            'Authorization': 'Bearer ' + token,
                        }
                    }).done(function (response) {

                        html += getPropertyHtml("Namn", response.displayName);
                        html += getPropertyHtml("Titel", response.jobTitle);
                        html += getPropertyHtml("Avdelning", response.officeLocation);
                        html += getPropertyHtml("Telefon jobb", response.businessPhones);
                        $("#results").html(html);
                        return postDataToContentControlers(response);


                    }).fail(function (response) {
                       // app.showNotification('Inloggningen slutade att fungera!', 'Du får logga ut och prova att logga in igen'); //response.responseText
                    }).always(function () {
                        console.log("AJAX is done!!")
                    })


                });
            } else {
                app.showNotification('Error:', 'Något gick fel. Du får logga in igen.'); //result.error.message
            }
        }
    );
}

在本地wordklient上它可以在Word上运行(Office 365 Pro Plus v.1609) 我在运行函数getDataFromSelection();

时得到了这个

Error from console

在我登录之前,我得到了确认和一个代币:

Token

当您使用microsoft-graph来获取邮件消息时,将处理参数ConversationId。每封邮件都有一个会话ID ...为什么抱怨对https://graph.microsoft.com/v1.0/me进行GET?

有谁知道如何解决这个问题或指出我正确的方向?谢谢=)

编辑:我忘了提到这可以在谷歌Chrome上在线工作,但在微软边缘上弹出窗口在登录之前甚至无法获取任何数据。只能再次弹出插件。

0 个答案:

没有答案