contentful - 无法获取条目列表:找不到资源(内容)
问题描述
我正在尝试根据 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
依赖项
解决方案
所以我最后做的是去java的内容交付API参考:
我按照示例按内容类型查询条目
我修改了下面的网址以适合我的用例:
/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);
}
}
这终于对我有用。
推荐阅读
- flutter - 颤振错误LateInitializationError:字段'animationStatus'尚未初始化
- reactjs - 如何在电容器顶部运行的 React Ionic 项目中插入图像?
- jasmine - 在另一个函数中模拟一个函数
- java - 使用java提取日志文件中两个时间戳之间的行
- python - 使用最小堆的列表中的第 K 个最大元素
- reactjs - 如何将(手动)接口构造从 React tsx 翻译成 React jsx?
- triggers - 在 arm 模板中使用时区触发 azure 数据工厂无法正常工作
- reactjs - 使用 DualList 组件呈现和添加数据时出现问题
- firebase - Firebase 可调用函数失败
- typescript - 打字稿扩展原始类型