[英]how to connect to office 365 outlook calender using javascript
how can i connect to office 365 using REST API from visual studio project, from past one week i was trying to connect office 365 using its API 我如何使用Visual Studio项目中的REST API连接到Office 365,从过去的一周开始,我一直在尝试使用其API连接Office 365
function accessO365() {
alert("Acces O365 method called");
var authContext;
var authToken; // for use with creating an outlookClient later.
authContext = new O365Auth.Context();
authContext.getIdToken("https://outlook.office365.com/")
.then((function (token) {
authToken = token;
// The auth token also carries additional information. For example:
userName = token.givenName + " " + token.familyName;
}).bind(this), function (reason) {
console.log('Failed to login. Error = ' + reason.message);
});
// Once the authToken has been acquired, create an outlookClient. One place to do this is inside of the
// ".then" function callback of authContext.getIdToken(...) above.
var outlookClient = new Microsoft.OutlookServices.Client('https://outlook.office365.com/api/v1.0', authToken.getAccessTokenFn('https://outlook.office365.com'));
outlookClient.me.events.getEvents().fetch().then(function (result) {
result.currentPage.forEach(function (event) {
console.log('Event "' + event.subject + '"')
});
}, function (error) {
console.log(error);
});
}
this was the code i was using previously in VS project but it is showing as undefined o365auth? 这是我以前在VS项目中使用的代码,但显示为未定义的o365auth? how can i resolve this and is there any better way to connect to office 365 using javascript 我该如何解决这个问题,有没有更好的方法使用JavaScript连接到Office 365
Here is the code to access calender events using unified o365 api: 这是使用统一的o365 api访问日历事件的代码:
// The code sample below demonstrates how to get events using the Office 365 unified API (Preview). //下面的代码示例演示如何使用Office 365统一API(预览)获取事件。
$.ajax('https://graph.microsoft.com/beta/me/Events', {
headers: {
Authorization: 'Bearer {token:https://graph.microsoft.com/}',
Accept: 'application/json;odata.metadata=none',
}
}).then(function (response) {
for (var i = 0; i < response.value.length; i++) {
console.log('Event "' + response.value[i].Subject + '"');
}
console.log('\n' + 'Full JSON response:')
console.log(response);
}).fail(function (error) {
console.log(error);
});
Before getting the events, make sure that you have a valid access token. 在获取事件之前,请确保您具有有效的访问令牌。
Here is an oauth sandbox where you can test your requests: 这是一个oauth沙箱,您可以在其中测试您的请求:
https://oauthplay.azurewebsites.net/ https://oauthplay.azurewebsites.net/
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.