gpt4 book ai didi

php - Magento 2 API 总是返回 Consumer is not authorized to access %resources

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:40:44 24 4
gpt4 key购买 nike

我正在尝试使用 Magento 2 rest API,但即使只是从命令行 curl'ing,我得到的唯一响应是 Consumer is not authorized to access %resources

我设法得到了一个 token

curl -X POST "http://magento.dev.blackorange.nl/index.php/rest/V1/integration/admin/token" \
-H "Content-Type:application/json" \
-d '{"username":"adminuser", "password":"adminpass"}'`

但是当我尝试

curl -X GET -H "Authorization: Bearer TOKEN" "http://magento.dev.blackorange.nl/rest/V1/products" 

(或任何其他端点)我收到-Consumer is not authorized to access %resources 消息

我是不是漏掉了一步?

最佳答案

确保您使用的是 Magento2 管理员用户名密码,而不是任何 API 用户名密码 如果这不起作用,则将适当的角色分配给该用户尝试更改 ROLE : ALL

要访问 GET/V1/products,您需要将 searchCriteria 参数作为必需参数传递。

首先你需要调用 admin/token API你从这里得到的 token 你需要传入第二个 API

TOKEN 替换为您第一次调用的 token key

curl -X GET -H "Authorization: Bearer ntfw****avefg***6mil***kysnl3***" "http://magento.dev.blackorange.nl/rest/V1/products" 

对于所有 REST API 引用:http://devdocs.magento.com/swagger/index.html#/

关于php - Magento 2 API 总是返回 Consumer is not authorized to access %resources,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37884687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com