【问题标题】:Get all entries with included images using Contentful REST API使用 Contentful REST API 获取包含图像的所有条目
【发布时间】:2018-05-28 17:36:05
【问题描述】:

我正在使用 typescript 和 Contentful-ManagementAPI(这就是我不使用 SDK 客户端的原因),并且我想从特定类型中检索所有条目。我这样称呼 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? 我将不胜感激任何帮助。谢谢

【问题讨论】:

    标签: contentful contentful-management


    【解决方案1】:

    来自内容丰富的文档:

    CMA 不支持 include 和 locale 参数。

    所以,我可能会更好地使用交付 api 来检索内容,并使用管理 api 来创建/更新/删除。这就是它应该使用的方式。

    【讨论】:

      【解决方案2】:

      可以在 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)的实际资产,您必须使用 includes.Asset 对象中的引用 ID (222xxm9aaAu4GiAc2ESw0Q) 找到正确的资产。

      【讨论】:

      • 我似乎在我的回复中找不到包含数组
      • 它与 items 数组处于同一级别。您如何阅读回复?
      • 我循环了response.data
      • 查看 Oscar Cabrera Rodriguez 的回复。您正在调用不包含引用的内容管理 API。我错过了。如果您只阅读内容,则应考虑使用传递 api(cdn.contentful.com 而不是 api.contentful.com),其中包含参考。否则,唯一的选择是单独调用以通过 id 获取您想要 URL 的资产。
      • 原来我已经回答了我自己的问题:)。无论如何,谢谢你的帮助
      【解决方案3】:

      尝试 include=10,如果您使用多语言环境,请为每个语言环境提供后备。 这对我有用。

      【讨论】:

        猜你喜欢
        • 2018-08-09
        • 1970-01-01
        • 2023-01-25
        • 1970-01-01
        • 2011-09-26
        • 2021-08-22
        • 1970-01-01
        • 2016-10-15
        • 1970-01-01
        相关资源
        最近更新 更多