【问题标题】:API Endpoints in Strapi V4Strapi V4 中的 API 端点
【发布时间】:2022-08-04 21:53:50
【问题描述】:

我是新的到 Strapi 并关注 Youtube 中的 Strapi 教程播放列表。Youtube 播放列表很旧,他正在使用 Strapi V3。但当前版本是4.0.5。我在使用API Endpoint 时遇到问题。

我建立收藏键入并将其命名为Posts。我什至发布了它。当我导航到http://localhost:1337/api/posts时,它返回

{
  \"data\": null,
  \"error\": {
    \"status\": 403,
    \"name\": \"ForbiddenError\",
    \"message\": \"Forbidden\",
    \"details\": {}
  }
}

有人帮我吗?

    标签: strapi


    【解决方案1】:

    如果您尝试以公共用户的身份检索数据,则需要转到角色并设置适当的权限。

    设置 -> 用户和权限 -> 角色 -> 公开 -> 帖子

    然后确保检查 find 和 Fineone。

    【讨论】:

      【解决方案2】:

      对我来说,问题是我需要为路由的auth 配置设置scope

      像这样(请注意scope):

        routes: [
          {
            method: 'GET',
            path: '/custom-route',
            handler: 'custom-controller.getCustomMethod',
            config: {
              policies: [],
              auth: {
                scope: ['find'],
              },
            },
          },
        ],
      

      【讨论】:

        猜你喜欢
        • 2022-08-22
        • 2022-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-10
        • 1970-01-01
        相关资源
        最近更新 更多