0

我正在尝试验证并从我的 Outlook 日历中获取事件。我能够登录并验证用户身份,但是当我尝试获取事件时,遇到了跨源问题。

这是我的代码片段:

<button id="SignIn" onclick="signIn()">Sign In</button>
 <h4 id="WelcomeMessage"></h4>
  
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.12/js/adal.min.js"></script>
<script>
  var ADAL = new AuthenticationContext({
      instance: 'https://login.microsoftonline.com/',
      tenant: 'common', //COMMON OR YOUR TENANT ID

      clientId: '<its my client id>', //This is your client ID
      redirectUri: 'http://localhost:8000', //This is your redirect URI

      callback: userSignedIn,
      popUp: true
  });

	window.authContext = new AuthenticationContext(ADAL);

    var isCallback = authContext.isCallback(window.location.hash);
    authContext.handleWindowCallback();
  
  function signIn() {
      ADAL.login();
  }

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

  function showWelcomeMessage() {
      var user = ADAL.getCachedUser();
      var divWelcome = document.getElementById('WelcomeMessage');
      divWelcome.innerHTML = "Welcome " + user.profile.name;
	  loadEvents();
  }

  function loadEvents() {
  console.log("in load events");
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "https://outlook.office.com/api/v2.0/me/calendarview?startDateTime=2016-10-01T01:00:00&endDateTime=2016-10-31T23:00:00&$select=Subject", true);
  xhr.send();}
</script>

最后运行脚本后这是我的错误。

这是我的错误

任何帮助表示赞赏。谢谢

4

1 回答 1

0

这是一种可能性:您的令牌对 outlook.office365.com 有效,但现在您正尝试使用 outlook.office.com。要检查这是否是您的情况,请检查 localStorage 或 sessionStorage。请看下图:在此处输入图像描述

于 2017-05-09T15:59:13.720 回答