如何从Magento 1.7 REST API获取访问令牌和访问令牌秘密

时间:2012-11-07 04:57:10

标签: php api magento rest magento-1.7

我已在我的magento admin上注册了我的应用程序。

已经获得了消费者密钥和消费者秘密。

但我没有运气获取访问令牌和访问令牌秘密。

它说

  

oauth_problem = parameter_absent&安培; oauth_parameters_absent = oauth_consumer_key

Simple REST API

我正在根据此链接进行测试

http://www.magentocommerce.com/api/rest/testing_rest_resources.html

我需要知道的答案是

  1. 我必须填写什么标题&数据文本字段?
  2. 如何获取访问令牌和访问机密令牌(在Mozilla上)?
  3. 是否有任何教程一步一步地测试任何REST API?

1 个答案:

答案 0 :(得分:8)

0)将https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo安装到Chrome

1)使用以下命令获取oAuth客户端工具:

sudo gem install oauth

2)设置Magento服务器

3)获取oAuth令牌

oauth \
  --verbose \
   --query-string \
   --consumer-key v484mnii2jyswedm6uo2cfcjay7uy49snws \
   --consumer-secret koay6845che7giy5lr17gnrhckkbhf8h5 \
   --access-token-url http://www.yourstore.com/magento/oauth/token \
   --authorize-url http://www.yourstore.com/magento/oauth/authorize \
   --request-token-url http://www.yourstore.com/magento/oauth/initiate \
   authorize

回复:

Server appears to support OAuth 1.0a; enabling support.
Please visit this url to authorize:
http://www.yourstore.com/magento/oauth/authorize?oauth_token=ey6fokp0pbzwr1016eb528y5xw1ak5ji

Please enter the verification code provided by the SP (oauth_verifier):
YOUR_CODE_HERE

Response:
  oauth_token_secret: g9kyz8c7zv868d58eav1muih3gxvq763
  oauth_token: aqvlfv9tuexn0mqiydgkaff4ixxg8743c

4)进行API调用

oauth \
    --consumer-key v484mnii2jyswedm6uo2cfcjay7uy49snws \
    --consumer-secret koay6845che7giy5lr17gnrhckkbhf8h5 \ 
    --token aqvlfv9tuexn0mqiydgkaff4ixxg8743c \
    --secret g9kyz8c7zv868d58eav1muih3gxvq763 \ 
    --uri http://www.yourstore.com/magento/api/rest/products \
    debug

尝试http://www.yourstore.com/magento/api/rest/products


找到解决方案

  

http://www.aschroder.com/2012/04/introduction-to-the-magento-rest-apis-with-oauth-in-version-1-7/

for php

  

https://gist.github.com/2469319