使用C#和Microsoft.Graph nuget创建使用Room作为位置的图形事件

时间:2018-01-10 00:11:52

标签: c# calendar microsoft-graph

不确定如何在C#和Microsoft.Graph中使用房间进行定位。

我想创建一个将事件放在房间里的事件。我现在是房间的电子邮件 - Rainier@M365x947151.onmicrosoft.com。我尝试的代码如下使用Microsoft.Graph。

        Microsoft.Graph.PhysicalAddress address = new Microsoft.Graph.PhysicalAddress();
        Microsoft.Graph.Location loc = new Location();
        loc.Address = address;
        loc.DisplayName = "Rainier conf room";
        loc.LocationEmailAddress = rainier;

        var newEvent = new Event();
        newEvent.Subject = subject + DateTime.Now.ToLongDateString();
        newEvent.Location = loc;
        newEvent.Attendees = attendees;
        newEvent.Body = eventBody;
        newEvent.Start = eventStartTime;
        newEvent.End = eventEndTime;

        Microsoft.Graph.Event createdEvent = null;
        try
        {
            // graphclient is passed into this method
            // var graphClient = AuthenticationHelper.GetAuthenticatedClient();
            // var graphClient = devfish.Graph.AuthenticationHelper.MyGraphClient;

            createdEvent = await graphClient.Me.Events.Request().AddAsync(newEvent);

我发送的有效负载应该看起来像这样,但它看起来不像是下面的。 Outlook不会将其视为“房间”。感谢...

我们想要付费 - 请注意odatatype和microsoft.graph.physicaladdress ...

{
  "subject": "Test meeting",
  "body": {
    "contentType": "HTML",
    "content": "Does this work (note the dates are in the past)?"
  },
  "start": {
      "dateTime": "2017-12-01T12:00:00",
      "timeZone": "Pacific Standard Time"
  },
  "end": {
      "dateTime": "2017-12-01T14:00:00",
      "timeZone": "Pacific Standard Time"
  },
  "location":{
    "address": {"@odata.type": "microsoft.graph.physicalAddress"},
    "displayName": "Rainier conf room"
  },
  "attendees": [
    {
      "emailAddress": {
        "address":"joseph.healy@microsoft.com",
        "name": "Joe"
      },
      "type": "required"
    },
    {
      "emailAddress": {
        "address":"Rainier@M365x947151.onmicrosoft.com",
        "name": "Rainier"
      },
      "type": "Resource"
    }
  ]
}

但是当使用C#graph创建时,有效负载看起来像这样。

{
    "subject": "23: 42:39: BASKETBALL IS OUR SUBJECT FOR TODAYTuesday, January 9, 2018",
    "body": {
        "contentType": "text",
        "content": "Status updates, blocking issues, and next steps"
    },
    "start": {
        "dateTime": "2017-12-01T19:30:00.0000000",
        "timeZone": "UTC"
    },
    "end": {
        "dateTime": "2017-12-01T20:00:00.0000000",
        "timeZone": "UTC"
    },
    "location": {
        "displayName": "Rainier conf room",
        "locationEmailAddress": "Rainier@M365x947151.onmicrosoft.com",
        "address": {}
    },
    "attendees": [
        {
            "type": "required",
            "emailAddress": {
                "address": "alexw@m365x947151.onmicrosoft.com"
            }
        },
        {
            "type": "required",
            "emailAddress": {
                "address": "maria@fabrikam.com"
            }
        },
        {
            "type": "resource",
            "emailAddress": {
                "address": "Rainier@M365x947151.onmicrosoft.com"
            }
        }
    ]
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

要获得所需的有效负载,您需要:

  1. 删除loc.LocationEmailAddress = rainier;
  2. 将键值“@ odata.type”,“microsoft.graph.physicalAddress”添加到 location.AdditionalData。我们最近还有其他人要求 自动@ odata.type生成所以这是一个额外的数据点 为了那个原因。
  3. 将name属性添加到会议室emailAddress对象。