我的代码......
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
}}
答案 0 :(得分:0)
看看AuthenticationHelper.cs class。 Scopes数组仅包含User.Read和Mail.Send权限。要读取日历事件,您需要请求Calendars.Read范围。如果您想知道如何执行其他操作并请求其他范围,您还可以查看uwp-snippets-rest sample。另请查看Microsoft Graph permission scopes document以获取可用权限范围的列表以及每个范围启用的操作。