首页 > 解决方案 > 无法获取条目列表:找不到资源(内容)

问题描述

我正在尝试根据 category_type 检索条目列表,但出现以下异常:

I/flutter ( 8486): Cannot get list of entries. Finished with error: {
I/flutter ( 8486):   "sys": {
I/flutter ( 8486):     "type": "Error",
I/flutter ( 8486):     "id": "NotFound"
I/flutter ( 8486):   },
I/flutter ( 8486):   "message": "The resource could not be found.",
I/flutter ( 8486):   "requestId": "883045ce-dcc2-4187-ab1d-28c57ad18756"
I/flutter ( 8486): }
I/flutter ( 8486): null

这是调用代码:

Future<List<Category>> getCategories() async {
  try {
     final entries = await _contentfulClient.getEntries<Category>(
      params: {
        'content_type': 'category',
        'skip': '0',
        'limit': '100',
        'order': 'sys.createdAt',
    },
  );

    return entries.items.asList();
  } catch(exception){
    print(exception.message);
  }
}

content_type 名称正确,拼写没有错误。

我尝试了不同的代码来获取有关我尝试访问的空间的信息,并且效果很好:

Future<Space> getCurrentSpaceDetails() async {
  try {
    return await _contentfulClient.getSpaceDetails(
      spaceid: Secrets.CONTENTFUL_SPACE_ID);
  } on ContentfulError catch (error) {
  throw ContentfulError(message: error.message);
  }
 }

输出:

I/flutter ( 8486): Space {
I/flutter ( 8486):   sys=SystemFields {
I/flutter ( 8486):     id=5k4zwxslsof9,
I/flutter ( 8486):     type=Space,
I/flutter ( 8486):   },
I/flutter ( 8486):   locales=[Locale {
I/flutter ( 8486):     code=en-US,
I/flutter ( 8486):     name=English (United States),
I/flutter ( 8486):     isDefault=true,
I/flutter ( 8486):   }],
I/flutter ( 8486):   name=afro-quiz,
I/flutter ( 8486): }

所以我认为这与安装没有任何关系。

我正在使用contentful_dart 0.0.5 依赖项

标签: contentfulcontentful-api

解决方案


所以我最后做的是去java的内容交付API参考:

https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/content-type/query-entries/console/java

我按照示例按内容类型查询条目

我修改了下面的网址以适合我的用例:

/spaces/{space_id}/environments/{environment_id}/entries?access_token={access_token}&content_type={content_type}

最后结果:

 Future getAllCategories(String spaceId,
   String accessToken, String contentTypeId) async {

   try {
     final response = await _contentfulClient.client.get(
         'https://$_baseUrl/spaces/$spaceId/environments/$_baseEnvironment

          /entries?access_token=$accessToken&content_type=$contentTypeId');
        return response.body;
   } catch (exception) {

     print(exception.message);
   }
 }

这终于对我有用。


推荐阅读