Universal Windows App (UWP) office 365 API - 使用 rest API 读取日历事件

Universal Windows App (UWP) office 365 API - Read calendar event using rest API

我的代码...

 HttpClient client = new HttpClient();
                var token = await AuthenticationHelper.GetTokenForUserAsync();
                client.DefaultRequestHeaders.Add("Accept", "application/json");
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);

                HttpResponseMessage response = await client.GetAsync(new Uri("https://graph.microsoft.com/v1.0/me/events"));

                if (!response.IsSuccessStatusCode)
                {

                    throw new Exception(response.StatusCode.ToString());
                }

我用过这个文档 https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/user_list_events

还有这个github例子 https://github.com/microsoftgraph/uwp-csharp-connect-rest-sample

我遇到了这个错误..

{StatusCode: 403, ReasonPhrase: 'Forbidden', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  client-request-id: 0de835e0-91d0-444d-bddc-a00b0d270eeb
  Server: Microsoft-IIS/8.5
  request-id: 0de835e0-91d0-444d-bddc-a00b0d270eeb
  Transfer-Encoding: chunked
  x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"South India","Slice":"SliceA","ScaleUnit":"002","Host":"AGSFE_IN_2","ADSiteName":"MAA"}}
  Duration: 1047.8402
  Cache-Control: private
  Date: Mon, 26 Sep 2016 06:55:15 GMT
  X-Powered-By: ASP.NET
  Content-Type: application/json
}}

查看 AuthenticationHelper.cs class. The Scopes array includes only the User.Read and Mail.Send permissions. In order to read calendar events, you'll need to request the Calendars.Read scope. You can also look at the uwp-snippets-rest sample if you want to know how to perform other operations and request additional scopes. Also take a look at the Microsoft Graph permission scopes document 以获得可用权限范围和每个范围启用的操作的列表。