[英]Trying to get all records of a generic list using Sharepoint and Microsoft Graph api
When trying to get records of a list in SharePoint i keep getting Response like: 当尝试在SharePoint中获取列表的记录时,我一直在收到类似的响应:
{"@odata.context":"https://graph.microsoft.com/beta/$metadata#users('123')/sharepoint/sites('456')/lists('789')/items","value":[]}
I was able to run through all sites and lists but still fail on items. 我能够遍历所有站点和列表,但在项目上仍然失败。 The list has the GenericList template.
该列表具有GenericList模板。 However on another list with the template DesignCatalog i were able to get all items.
但是在模板DesignCatalog的另一个列表中,我能够获取所有项目。 Is "/items" the wrong way to get records of a generic list?
“ / items”是获取通用列表记录的错误方法吗?
Here is a snippet of my current Code: 这是我当前代码的摘要:
const string serviceEndpoint = "https://graph.microsoft.com/beta/";
HttpClient client = new HttpClient();
var token = await _authenticationHelper.GetTokenAsync();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
// get the site
HttpResponseMessage responseGetSites = await client.GetAsync(new Uri(serviceEndpoint + "sharePoint:/Intranet"));
if (responseGetSites.IsSuccessStatusCode)
{
string responseContent = await responseGetSites.Content.ReadAsStringAsync();
var jResult = JObject.Parse(responseContent);
siteItem = JsonConvert.DeserializeObject<SiteItemModel>(jResult.ToString());
// get all lists with the given site id
HttpResponseMessage responseGetLists = await client.GetAsync(new Uri(serviceEndpoint + "sharepoint/sites/" + siteItem.SiteId + "/lists"));
if (responseGetLists.IsSuccessStatusCode)
{
string responseContent2 = await responseGetLists.Content.ReadAsStringAsync();
var jResult2 = JObject.Parse(responseContent2);
foreach (JObject listresponse in jResult2["value"])
{
ListItemModel desiralizedItemModel = JsonConvert.DeserializeObject<ListItemModel>(listresponse.ToString());
listItemCollection.Add(desiralizedItemModel);
}
// find a specific list
string listId = listItemCollection.Where(w => w.listName == "MyTestlist").First().listId;
// get all records with of the given list
HttpResponseMessage responseGetItems = await client.GetAsync(new Uri(serviceEndpoint + "sharepoint/sites/" + siteItem.SiteId + "/lists/" + listId + "/items"));
if (responseGetItems.IsSuccessStatusCode)
{
string responseContent3 = await responseGetItems.Content.ReadAsStringAsync();
var jResult3 = JObject.Parse(responseContent3);
I had the same problem. 我有同样的问题。 I had to add "Sites.ReadWrite.All" permission under MS Graph, not under sharepoint (I was writing to the list as well, but "Sites.Read.All" should work).
我必须在MS Graph下(而不是在共享点下)添加“ Sites.ReadWrite.All”权限(我也在向列表中写入内容,但“ Sites.Read.All”应该可以工作)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.