Microsoft Graph SDK和SharePoint列表项

时间:2018-03-18 15:21:01

标签: c# sharepoint sdk microsoft-graph

我正在尝试使用此功能从SharePoint Projectsite中的任务列表中检索所有项目:

    public async Task<string> GetTasks(GraphServiceClient graphClient, string siteId, string listId)
    {
        string requestUrl = "https://graph.microsoft.com/v1.0/sites/" + siteId + "/lists/" + listId + "/items?expand=fields";

        HttpRequestMessage hrm = new HttpRequestMessage(HttpMethod.Get, requestUrl);

        await graphClient.AuthenticationProvider.AuthenticateRequestAsync(hrm);

        HttpResponseMessage response = await graphClient.HttpProvider.SendAsync(hrm);

        if (response.IsSuccessStatusCode)
        {
            string content = await response.Content.ReadAsStringAsync();
            return content;
        }
        else
            throw new ServiceException(
                new Error
                {
                    Code = response.StatusCode.ToString(),
                    Message = await response.Content.ReadAsStringAsync()
                });
    }

但响应内容为空:

@ odata.context “:”https://graph.microsoft.com/v1.0/ $元数据#网站( 'xxxxxxxxxx.com%2Cde7be133-babf-4bc9-8e52-857657f8fdd6%2C379cb706-d430-4dfc-8347-f2c8bc92a38c')/列表(” eca2429f-44b7-4d68-af81-f5e56fece3ab')/项目”, “值”:[]}

我不明白为什么回答是空的。在Graph Explorer中,它返回数据。有人可以解释一下吗?

由于

1 个答案:

答案 0 :(得分:1)

由于您查询SharePoint List Items,因此需要指定Sites.Read.AllSites.ReadWrite.All权限范围。

根据documentation

  

Sites.Read.All阅读所有网站集中的项目

每个列表类型的权限范围:

  • SharePoint列表:Sites.Read.AllSites.ReadWrite.All
  • SharePoint库:Files.Read.AllFiles.ReadWrite.All