使用 Contentful REST API 获取包含图像的所有条目
Get all entries with included images using Contentful REST API
我正在使用 typescript 和 Contentful-ManagementAPI(这就是我不使用 SDK 客户端的原因),我想从特定类型中检索所有条目。我这样调用 th Api :
axios.get("https://api.contentful.com/spaces/" +
space_id +
"/entries?content_type=" +
content_type+"&include="+2)
我收到了所有请求的条目,但在图像字段中我得到的是:
poster:en-US:
sys:
{type: "Link", linkType: "Asset", id: "222xxm9aaAu4GiAc2ESw0Q"}
那么,我怎样才能得到图像 URL?
我将不胜感激任何帮助。谢谢
引用的资产和条目可以在 API 响应的 includes
对象中找到。
响应应如下所示:
{
"sys": {
"type": "Array"
},
"total": 9,
"skip": 0,
"limit": 100,
"items": [ // Your items here ],
"includes": {
"Asset": [ // Your included assets here, this is where you find the url to the image ]
"Entry": [ // Any referenced entries not included in the items array above ]
}
因此,要找到包含所有数据(包括 url)的实际资产,您必须使用参考 ID (222xxm9aaAu4GiAc2ESw0Q) 在 includes.Asset
对象。
来自内容丰富的文档:
The CMA does not support the include and locale parameters.
因此,我最好使用传送 api 检索内容,并使用管理 api create/update/delete。就应该这样使用。
尝试 include=10,如果您使用多语言环境,请为每个语言环境提供回退。
这对我有用。
我正在使用 typescript 和 Contentful-ManagementAPI(这就是我不使用 SDK 客户端的原因),我想从特定类型中检索所有条目。我这样调用 th Api :
axios.get("https://api.contentful.com/spaces/" +
space_id +
"/entries?content_type=" +
content_type+"&include="+2)
我收到了所有请求的条目,但在图像字段中我得到的是:
poster:en-US:
sys:
{type: "Link", linkType: "Asset", id: "222xxm9aaAu4GiAc2ESw0Q"}
那么,我怎样才能得到图像 URL? 我将不胜感激任何帮助。谢谢
引用的资产和条目可以在 API 响应的 includes
对象中找到。
响应应如下所示:
{
"sys": {
"type": "Array"
},
"total": 9,
"skip": 0,
"limit": 100,
"items": [ // Your items here ],
"includes": {
"Asset": [ // Your included assets here, this is where you find the url to the image ]
"Entry": [ // Any referenced entries not included in the items array above ]
}
因此,要找到包含所有数据(包括 url)的实际资产,您必须使用参考 ID (222xxm9aaAu4GiAc2ESw0Q) 在 includes.Asset
对象。
来自内容丰富的文档:
The CMA does not support the include and locale parameters.
因此,我最好使用传送 api 检索内容,并使用管理 api create/update/delete。就应该这样使用。
尝试 include=10,如果您使用多语言环境,请为每个语言环境提供回退。 这对我有用。