我们有旧版代码,可将自定义数据写入Outlook AppointmentItem对象的“ UserProperties”集合。现在,我们已切换为使用Web上的Outlook(OWA)。
使用MS Graph,如何检索这些值?
我一直在浏览本文档(Outlook extended properties overview),但无法正常使用。我正在使用MS Graph Explorer。
这是我要检索信息自定义数据的事件。
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#users('45d5e17d-348a-4ca8-b53c-c7d353b928b3')/events",
"value": [
{
"@odata.etag": "W/\"GKUifH9QgE6zbEa7VG6rswABBwIJDw==\"",
"id": "AAMkADU4MzkxN2RmLTdiZDAtNDIwYS04NjQzLTUzNzMyMjM0Y2VkNQBGAAAAAABGjw0ByCaySL6aUxJmew3qBwDwiT27qO5xT6RMWiWBhwRzAAAADIqqAADdUihFgnKFTYATejxXFszxADsYsAgxAAA=",
"createdDateTime": "2018-07-11T19:17:12.340183Z",
"lastModifiedDateTime": "2018-09-17T19:50:10.7118964Z",
我假设此事件的“ id”值就是我应该使用的值。
这是我正在进行的REST调用(注意:使用BETA)
https://graph.microsoft.com/beta/me/events('AAMkADU4MzkxN2RmLTdiZDAtNDIwYS04NjQzLTUzNzMyMjM0Y2VkNQBGAAAAAABGjw0ByCaySL6aUxJmew3qBwDwiT27qO5xT6RMWiWBhwRzAAAADIqqAADdUihFgnKFTYATejxXFszxADsYsAgxAAA=')?$expand=SingleValueExtendedProperties($filter=id%20eq%20'Integer%20{0006303D-0000-0000-C000-000000000046}%20Name%20TaskID' )
UserProperty名称为“ TaskID”,其中包含一个整数。我不清楚GUID值应该是什么。
我已经尝试过AppointmentItem本身的GUID。然后是AppointmentItem中包含的“ UserProperty”集合的GUID,最后是“ UserProperty”集合中包含的“ UserProperty”属性的GUID。什么都没有。
有任何线索吗?
尝试使用Microsoft Graph检索此数据
using System;
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace AddCustomProperty
{
public partial class ThisAddIn
{
Outlook.Items _items;
Outlook.Folder _calendar;
Outlook.Inspectors _inspectors;
const string sCustomData = "MyCustomData";
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
_calendar = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder;
_items = _calendar.Items;
_items.ItemChange += eventChange;
_inspectors = this.Application.Inspectors;
_inspectors.NewInspector += newInspectorWindow;
}
private void newInspectorWindow(Outlook.Inspector Inspector)
{
Object oAppointmentItem = null;
Outlook.UserProperties userProperties = null;
Outlook.UserProperty userProperty = null;
try
{
oAppointmentItem = Inspector.CurrentItem;
if (oAppointmentItem is Outlook.AppointmentItem)
{
userProperties = ((Outlook.AppointmentItem)oAppointmentItem).UserProperties;
userProperty = userProperties.Find(sCustomData);
if( userProperty != null)
{
((Outlook.AppointmentItem)oAppointmentItem).Body = string.Format("MY CUSTOM DATA FOUND [{0}]: {1}\n", DateTime.Now, userProperty.Value);
}
}
}
catch(Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
finally
{
if (userProperty != null) { Marshal.ReleaseComObject(userProperty); userProperty = null; }
if (userProperties != null) { Marshal.ReleaseComObject(userProperties); userProperties = null; }
if (oAppointmentItem != null) { Marshal.ReleaseComObject(oAppointmentItem); oAppointmentItem = null; }
}
}
private void eventChange(object Item)
{
Outlook.AppointmentItem apptItem = null;
Outlook.UserProperties userProperties = null;
Outlook.UserProperty userProperty = null;
try
{
apptItem = Item as Outlook.AppointmentItem;
if (apptItem.Subject == "MS Graph - Extended Properties Test")
{
userProperties = apptItem.UserProperties;
userProperty = userProperties.Find(sCustomData);
if( userProperty == null)
{
userProperty = userProperties.Add(sCustomData, Outlook.OlUserPropertyType.olInteger);
userProperty.Value = 10;
}
else
{
((Outlook.AppointmentItem)apptItem).Body = string.Format("MY CUSTOM DATA FOUND [{0}]: {1}\n", DateTime.Now, userProperty.Value);
}
}
}
catch( Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
finally
{
if( userProperty != null) { Marshal.ReleaseComObject(userProperty); userProperty = null; }
if (userProperties != null) { Marshal.ReleaseComObject(userProperties); userProperties = null; }
}
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Note: Outlook no longer raises this event. If you have code that
// must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
答案 0 :(得分:0)
我在另一个网站上收到了答案。
问题在于我在其中一个查询中使用的GUID。我使用的是 UserProperty 对象的GUID,而不是使用继承自 UserProperty
的对象的GUID。正确的GUID来自MAPI对象本身。
最终呼叫如下:Complete Answer
https://graph.microsoft.com/v1.0/me/events('AAMkADU4MzkxN2RmLTdiZDAtNDIwYS04NjQzLTUzNzMyMjM0Y2VkNQBGAAAAAABGjw0ByCaySL6aUxJmew3qBwDwiT27qO5xT6RMWiWBhwRzAAAADIqqAAAYpSJ8f1CATrNsRrtUbquzAAEOAONsAAA=')?$expand=singleValueExtendedProperties($filter=id%20eq%20'Integer%20{00020329-0000-0000-C000-000000000046}%20Name%20MyCustomData')