Wordpress 用户 REST API 返回管理员角色的 rest_cannot_edit_roles

问题描述 投票:0回答:1

我在 WordPress 网站的 WooCommerce 设置中创建了一个 API 密钥和秘密,链接到具有管理员角色的用户。我能够成功使用此 API 密钥对网站进行各种 API 调用。

但是,当我尝试执行此 API 调用来更新用户角色时:

POST /wp-json/wp/v2/users/35

{
    "roles": ["technician"]
}

我收到了包含以下内容的 401 响应:

{
    "code": "rest_cannot_edit_roles",
    "message": "Sorry, you are not allowed to edit roles of this user.",
    "data": {
        "status": 401
    }
}

但是,正如已经提到的,与 API 调用中使用的 API 密钥关联的用户是管理员,拥有完全权限。我错过了什么?

wordpress-rest-api
1个回答
0
投票

我通过使用用户配置文件中配置的应用程序密码(而不是 WooCommerce API 密钥和秘密)对 API 调用进行身份验证来解决该问题。

© www.soinside.com 2019 - 2024. All rights reserved.