使用Contentful REST API获取包含图像的所有条目

时间:2018-05-28 17:36:06

标签: contentful contentful-management

我正在使用typescript和Contentful-ManagementAPI(这就是我不使用SDK客户端的原因),我想从特定类型中检索所有条目。我这样称呼Api: #include <iostream> #include <curand.h> #include <curand_kernel.h> #define cudaErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { if (code != cudaSuccess) { std::cerr << "cudaAssert: " << cudaGetErrorString(code) << " " << file << ": " << line << std::endl; if (abort) exit(code); } } __global__ void setup_curand_state (curandState *state, int seed, int dim) { int index = threadIdx.x+blockDim.x*blockIdx.x; if (index < dim) curand_init(seed, index, 0, &state[index]); } __global__ void set_random (float* to, curandState* curand_state, int dim) { int index = threadIdx.x+ blockIdx.x* blockDim.x; if (index < dim) to [index] = curand_normal (&curand_state[index]); } int main () { int dim = 100000; float *data; cudaErrchk (cudaMallocManaged ((void**) &data, dim * sizeof (float))); curandState* curand_state; cudaErrchk (cudaMalloc (&curand_state, (dim * sizeof (curandState)))); setup_curand_state <<<(dim + 1023) / 1024, 1024>>> (curand_state, time(NULL), dim); cudaErrchk (cudaDeviceSynchronize()); set_random <<<(dim + 1023) / 1024, 1024>>> (data, curand_state, dim); cudaFree (data); return 0; }

我收到了所有要求的条目,但在图片领域我得到了这个:

axios.get("https://api.contentful.com/spaces/" + space_id + "/entries?content_type=" + content_type+"&include="+2)

那么,我怎样才能获得图片网址? 我将不胜感激任何帮助。感谢

3 个答案:

答案 0 :(得分:0)

引用的资产和条目可以在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 ]
  }

因此,要查找包含所有数据(包括网址)的实际资产,您必须使用includes.Asset对象中的引用ID(222xxm9aaAu4GiAc2ESw0Q)找到正确的资产。

答案 1 :(得分:0)

来自Contentful docs:

  

CMA不支持include和locale参数。

因此,我可能会更好地使用传递API来检索内容,并使用管理API来创建/更新/删除。这是应该使用的方式。

答案 2 :(得分:0)

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