通用Windows应用程序(UWP)的Office 365 API - 读取日历事件使用REST API

问题描述:

我的代码...通用Windows应用程序(UWP)的Office 365 API - 读取日历事件使用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。 Scopes数组仅包含User.Read和Mail.Send权限。为了阅读日历事件,您需要请求Calendars.Read范围。如果您想知道如何执行其他操作并请求其他范围,则还可以查看uwp-snippets-rest sample。另请参阅Microsoft Graph permission scopes document以获取可用权限范围和每个范围启用的操作的列表。