消费者无权访问Magento2 rest API的%resources


9

我创建了一个新客户并获得了完美的令牌,但是当我尝试访问任何API时,例如

http://myhost.com/index.php/rest/V1/customers/me?Authorization=Bearerhy23vc01x9s1jd2t8gho47g58trllc0b 

得到了错误

<?xml version="1.0"?>
<response>
<message>Consumer is not authorized to access %resources</message>
<parameters>
<resources>self</resources>
</parameters>
  <trace>#0 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest/RequestValidator.php(70): Magento\Webapi\Controller\Rest\RequestValidator-&gt;checkPermissions()
#1 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest/InputParamsResolver.php(80): Magento\Webapi\Controller\Rest\RequestValidator-&gt;validate()
#2 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest.php(299): Magento\Webapi\Controller\Rest\InputParamsResolver-&gt;resolve()
#3 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest.php(216): Magento\Webapi\Controller\Rest-&gt;processApiRequest()
#4 /var/www/myhost.com/public_html/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\Webapi\Controller\Rest-&gt;dispatch(Object(Magento\Framework\App\Request\Http))
#5 /var/www/myhost.com/public_html/vendor/magento/framework/App/Http.php(135): Magento\Webapi\Controller\Rest\Interceptor-&gt;dispatch(Object(Magento\Framework\App\Request\Http))
#6 /var/www/myhost.com/public_html/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http-&gt;launch()
#7 /var/www/myhost.com/public_html/index.php(39): Magento\Framework\App\Bootstrap-&gt;run(Object(Magento\Framework\App\Http))
#8 {main}</trace>
</response>

请任何帮助

Answers:


10

授权令牌未放置在参数上。应该设置在标题上。这是有关POSTMAN的示例:

在此处输入图片说明

在cURL上,它将是:

curl -X GET --header "Accept: application/json" --header "Authorization: Bearer XXXXXXXXXX" "http://yoursite.com/rest/V1/products/:sku"

感谢您的答复,我已经在标头或url中的参数上进行了尝试,并且可以像products您和一样完美地用于某些api categories,但是对于某些API(如)V1/customers/me,我却收到了错误消息。即使我在终端机上卷曲,它也可以正常工作。我将邮递员和http请求者用于Firefox。
Jsparo30'2013/

我的测试网站上没有问题。在“载体”和令牌之间是否有空格?也许您的令牌已过期,试图获得一个新的
PY益

HHH,这是什么玩笑!没有空间和工作正常products,并categories为我所提到的,但当删除它customers/me工作得很好。请编辑答案,并添加删除空间部分以提供真实的答案。谢谢。
Jsparo30 2016年

实际上,它更可能是令牌过期。我使用旧令牌访问API,它显示了与您所提出的问题相同的错误。只需续签令牌即可解决问题。
PY Yick

@ Jsparo30您是否找到了解决方案,我也面临着同样的问题
Janarthanan Ramu
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.