从Microsoft Graph API请求列表项时接收到空数组 [英] Receiving an empty array when requesting list items from Microsoft Graph API
问题描述
我正在尝试使用Microsoft Graph通过JS应用程序上的获取请求来访问SharePoint列表的项目.
I'm trying to use Microsoft Graph to access the items of a SharePoint List with fetch requests on a JS application.
当我发出以下请求时:
export const getList = access_token => {
const token = "Bearer " + access_token;
const url = `${apiUrl}/${siteId}/lists/${listId}`;
return fetch(url, {
method: "get",
headers: {
Authorization: token,
Accept: "application/json;odata.metadata=none"
}
}).then(res => res.json());
};
我得到的是一个有效的JSON响应,其中包含有关所讨论列表的详细信息.
What I get is a valid JSON response with details about the list in question.
但是,当我使用此请求时:
However, when I use this request:
export const getItems = access_token => {
const url = `${apiUrl}/${siteId}/lists/${listId}/items`;
const token = "Bearer " + access_token;
return fetch(url, {
method: "get",
headers: {
Authorization: token,
Accept: "application/json;odata.metadata=none"
}
}).then(res => res.json());
};
我认为应该返回该列表中包含的项目的
,尽管列表不为空,但我得到一个带有空数组的响应.
which I think is supposed to return the items contained in that list, I get a response with an empty array, although the list is not empty.
我可能应该补充一点,我正在使用以下URL来获取访问令牌:
I probably should add that I'm using the following URL to get the access token:
const tokenUrl = `https://login.microsoftonline.com/${siteURL}/oauth2/v2.0/token`
我想念什么吗?
添加发出请求时收到的响应
Adding the responses received when making the requests
使用URL获取列表信息时:
When getting information of a list with the URL:
const url = `${apiUrl}/${siteId}/lists/${listId}`;
响应是以下对象:
{
createdBy: {user: {…}}
createdDateTime: "2018-09-13T04:01:11Z"
description: ""
displayName: "Pessoa"
eTag ""70c738b2-d857-4431-a079-bcc0c60efbe4,16""
id: "70c738b2-d857-4431-a079-bcc0c60efbe4"
lastModifiedDateTime: "2018-09-13T04:08:47Z"
list: {contentTypesEnabled: false, hidden: false, template: "genericList"}
name: "Pessoa"
parentReference: {}
webUrl: "https://incubadorahabits.sharepoint.com/sites/PlataformaTecnologica/Lists/Pessoa"
}
尝试获取带有URL的列表项时:
When trying to get the list items with the URL:
const url = `${apiUrl}/${siteId}/lists/${listId}/items`;
响应为:
{
value: []
}
https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items endpoint
的
推荐答案
Empty 结果通常表示缺少必需的权限. 要查询SharePoint列表项,根据列表类型,需要指定以下权限范围:
Empty results for https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items endpoint
usually means that required permissions are missing.
To query SharePoint list items, depending on the list type the following permission scope needs to be specified:
- 对于SharePoint 列表:
Sites.Read.All
或Sites.ReadWrite.All
- 对于SharePoint 库:
Files.Read.All
或Files.ReadWrite.All
- for SharePoint List:
Sites.Read.All
orSites.ReadWrite.All
- for SharePoint Library:
Files.Read.All
orFiles.ReadWrite.All
这篇关于从Microsoft Graph API请求列表项时接收到空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!