Невозможно получить список записей: ресурс не найден - PullRequest
0 голосов
/ 27 мая 2020

Я пытаюсь получить список записей на основе 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 зависимость

1 Ответ

0 голосов
/ 29 мая 2020

Итак, что я наконец сделал, это go для ссылок API доставки контента для java:

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

где я следовал примеру для запроса записей по типу контента

Я изменил URL-адрес ниже, чтобы он соответствовал моему варианту использования:

/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);
   }
 }

Это наконец сработало для меня.

...