我正在尝试验证并从我的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>
运行脚本后,这是我的错误。
感谢任何帮助。 感谢