Javascript 使用Graph API无法使用filter param获取特定日期的事件
这是我的程序发出的请求:Javascript 使用Graph API无法使用filter param获取特定日期的事件,javascript,microsoft-graph-api,Javascript,Microsoft Graph Api,这是我的程序发出的请求: https://graph.microsoft.com/v1.0/me/events?$filter=2018-07-15T01:00:00&$select=subject,start,end,createdDateTime&$orderby=createdDateTime%20DESC 400(错误请求)您试图使用对象中不存在的属性(startDateTime和endDateTime)筛选终结点。您还在filter子句中传递一个=,而不是eq 端点确实有startDa
https://graph.microsoft.com/v1.0/me/events?$filter=2018-07-15T01:00:00&$select=subject,start,end,createdDateTime&$orderby=createdDateTime%20DESC
400(错误请求)
您试图使用对象中不存在的属性(startDateTime
和endDateTime
)筛选终结点。您还在filter子句中传递一个=
,而不是eq
端点确实有startDateTime
和endDateTime
参数,但这些参数本身是查询参数(不是筛选子句的一部分)。我怀疑这就是你要找的行动:
var authEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?";
var redirectUri = "http://localhost:8080";
var appId = "SomethingSomething";
var scopes = "openid profile User.Read Mail.Read Calendars.Read";
function getUserEvents(callback) {
getAccessToken(function(accessToken) {
if (accessToken) {
// Create a Graph client
var client = MicrosoftGraph.Client.init({
authProvider: done => {
// Just return the token
done(null, accessToken);
}
});
// Get the 10 newest events
client
.api("/me/events")
.filter("startDateTime='2018-03-01'&endDateTime='2018-03-31'")
.select("subject,start,end,createdDateTime")
.orderby("createdDateTime DESC")
.get((err, res) => {
if (err) {
callback(null, err);
} else {
callback(res.value);
}
});
} else {
var error = { responseText: "Could not retrieve access token" };
callback(null, error);
}
});
}
您在末尾粘贴的请求不正确,因为没有
displayName
属性。但是,请检查代码的其余部分,因为很奇怪,您过滤了日期,并且在请求中看到了subject的过滤器。'client.api('/me/events').filter(“start/dateTime ge'2018-07-19T08:00')“**我已经更改了过滤器参数,现在它可以工作了**请记住,它只会显示主事件。使用/events
不会返回定期事件实例。这是否可以在outlook日历中获取所选约会(事件)数据。因为我需要在日历加载项中显示选定的日历视图数据。
client
.api("/me/calendarview")
.query({
startdatetime: "2018-03-01T00:00:00.0000000",
enddatetime: "2018-03-31T23:00:00.0000000"
})
.select("subject,start,end,createdDateTime")
.orderby("createdDateTime DESC")
.get((err, res) => {
if (err) {
callback(null, err);
} else {
callback(res.value);
}
});