如何使用 Java EWS API 搜索 iCalUid 的 Exchange 约会?
How to search for an Exchange appointment for an iCalUid using Java EWS API?
我正在使用 Java EWS library 通过 iCalUid
在用户的日历中搜索约会(例如 iCalUid
我有:040000008200E00074C5B7101A82E00800000000F66E2C0D59A9D001000000000000000010000000F7A6AACB779B00429164F39AE6DD6BB9
)。这是我的 Scala 代码:
import microsoft.exchange.webservices.data._
import java.net.URI
import java.util.Date
val exchange = {
val service = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
service.setUrl(new URI(host))
service.setCredentials(new WebCredentials(user, pass))
service
}
def calendarFolderFor(email: String) = new FolderId(WellKnownFolderName.Calendar, Mailbox.getMailboxFromString(email))
def findMatchingAppointments(iCalUid: String, email: String) = {
val searchFilter = new SearchFilter.IsEqualTo(AppointmentSchema.ICalUid, iCalUid)
exchange.findItems(calendarFolderFor(email), searchFilter, new ItemView(1)).getItems
}
以上代码抛出此错误:
microsoft.exchange.webservices.data.ServiceResponseException: The property can not be used with this type of restriction.
at microsoft.exchange.webservices.data.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:262) ~[ews-java-api-1.3-SNAPSHOT.jar:na]
at microsoft.exchange.webservices.data.ServiceResponse.throwIfNecessary(ServiceResponse.java:251) ~[ews-java-api-1.3-SNAPSHOT.jar:na]
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:146) ~[ews-java-api-1.3-SNAPSHOT.jar:na]
at microsoft.exchange.webservices.data.ExchangeService.findItems(ExchangeService.java:807) ~[ews-java-api-1.3-SNAPSHOT.jar:na]
at microsoft.exchange.webservices.data.ExchangeService.findItems(ExchangeService.java:851) ~[ews-java-api-1.3-SNAPSHOT.jar:na]
然后我尝试修改 this thread:
中的代码
def findMatchingAppointments(iCalUid: String, email: String) = {
import org.apache.commons.codec.binary.{Hex, Base64}
val searchFilter = new SearchFilter.IsEqualTo(
new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Appointment, 0x03, MapiPropertyType.Binary),
Base64.encodeBase64String(Hex.decodeHex(iCalUid.toCharArray))
)
val view = new ItemView(1)
view.setPropertySet(new PropertySet(BasePropertySet.FirstClassProperties, AppointmentSchema.ICalUid))
exchange.findItems(calendarFolderFor(email), searchFilter, view).getItems
}
但是,现在它没有抛出异常,但也没有找到约会。我知道约会存在,因为我使用以下代码片段暴力破解并找到了约会:
def bruteForceFind(start: Date, end: Date, iCalUid: String, email: String) = {
val view = new CalendarView(start, end, 100)
exchange.findAppointments(calendarFolderFor(email), view).getItems
val allAppointments = exchange.findAppointments(calendarFolderFor(email), view).getItems
allAppointments.filter(_.getICalUid == iCalUid)
}
我做错了什么?给定 iCalUid,如何为用户搜索约会?工作 Java/Scala 代码也可以。
显然会议和约会是有区别的。替换此行:
new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Appointment, 0x03, MapiPropertyType.Binary),
和
new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, 0x03, MapiPropertyType.Binary)
有效。
我正在使用 Java EWS library 通过 iCalUid
在用户的日历中搜索约会(例如 iCalUid
我有:040000008200E00074C5B7101A82E00800000000F66E2C0D59A9D001000000000000000010000000F7A6AACB779B00429164F39AE6DD6BB9
)。这是我的 Scala 代码:
import microsoft.exchange.webservices.data._
import java.net.URI
import java.util.Date
val exchange = {
val service = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
service.setUrl(new URI(host))
service.setCredentials(new WebCredentials(user, pass))
service
}
def calendarFolderFor(email: String) = new FolderId(WellKnownFolderName.Calendar, Mailbox.getMailboxFromString(email))
def findMatchingAppointments(iCalUid: String, email: String) = {
val searchFilter = new SearchFilter.IsEqualTo(AppointmentSchema.ICalUid, iCalUid)
exchange.findItems(calendarFolderFor(email), searchFilter, new ItemView(1)).getItems
}
以上代码抛出此错误:
microsoft.exchange.webservices.data.ServiceResponseException: The property can not be used with this type of restriction.
at microsoft.exchange.webservices.data.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:262) ~[ews-java-api-1.3-SNAPSHOT.jar:na]
at microsoft.exchange.webservices.data.ServiceResponse.throwIfNecessary(ServiceResponse.java:251) ~[ews-java-api-1.3-SNAPSHOT.jar:na]
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:146) ~[ews-java-api-1.3-SNAPSHOT.jar:na]
at microsoft.exchange.webservices.data.ExchangeService.findItems(ExchangeService.java:807) ~[ews-java-api-1.3-SNAPSHOT.jar:na]
at microsoft.exchange.webservices.data.ExchangeService.findItems(ExchangeService.java:851) ~[ews-java-api-1.3-SNAPSHOT.jar:na]
然后我尝试修改 this thread:
中的代码def findMatchingAppointments(iCalUid: String, email: String) = {
import org.apache.commons.codec.binary.{Hex, Base64}
val searchFilter = new SearchFilter.IsEqualTo(
new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Appointment, 0x03, MapiPropertyType.Binary),
Base64.encodeBase64String(Hex.decodeHex(iCalUid.toCharArray))
)
val view = new ItemView(1)
view.setPropertySet(new PropertySet(BasePropertySet.FirstClassProperties, AppointmentSchema.ICalUid))
exchange.findItems(calendarFolderFor(email), searchFilter, view).getItems
}
但是,现在它没有抛出异常,但也没有找到约会。我知道约会存在,因为我使用以下代码片段暴力破解并找到了约会:
def bruteForceFind(start: Date, end: Date, iCalUid: String, email: String) = {
val view = new CalendarView(start, end, 100)
exchange.findAppointments(calendarFolderFor(email), view).getItems
val allAppointments = exchange.findAppointments(calendarFolderFor(email), view).getItems
allAppointments.filter(_.getICalUid == iCalUid)
}
我做错了什么?给定 iCalUid,如何为用户搜索约会?工作 Java/Scala 代码也可以。
显然会议和约会是有区别的。替换此行:
new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Appointment, 0x03, MapiPropertyType.Binary),
和
new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, 0x03, MapiPropertyType.Binary)
有效。