简体   繁体   English

使用Magento REST API

[英]Using Magento REST API

I've searched all over (including here on Stackoverflow) for how to use the Magento REST API. 我在各处(包括此处的Stackoverflow上)进行了搜索,以了解如何使用Magento REST API。 I need help on getting an Unauthorized Request Token (the first step) 我需要获得未经授权的请求令牌的帮助(第一步)

On the Magento setup I'm using the REST API is working for GET Products for Guests so I know that is not [the problem][1] 在Magento设置上,我正在使用REST API的“来宾GET产品”功能正常,因此我知道这不是[问题] [1]

I have setup an OAuth Consumer for the above URL and have both the consumer key and secret. 我已经为上述URL设置了OAuth使用者,并且具有使用者密钥和秘密。 I can't figure out what URL to use for the Callback URL. 我无法弄清楚将哪个URL用于回调URL。

First, I'm stuck and don't know what I should use as the Callback URL when setting up the consumer. 首先,我很困惑,并且不知道在设置使用者时应使用什么作为回调URL。 It is an optional field in Magento 这是Magento中的可选字段

I'm testing with the Firefox REST Client as per http://www.magentocommerce.com/api/rest/testing_rest_resources.html 我正在按照http://www.magentocommerce.com/api/rest/testing_rest_resources.html使用Firefox REST客户端进行测试

Next with the Firefox REST client I can't get started by getting an Unauthorized Request Token. 接下来,使用Firefox REST客户端,我无法获得未授权的请求令牌。 According the above URL I should have the oauth_callback URI in the header. 根据上述URL,我应该在标头中包含oauth_callback URI。

The following request parameters should be present in the Authorization header: 授权标头中应包含以下请求参数:

oauth_callback - an URI to which the Service Provider will redirect the resource owner (user) after the authorization is complete. oauth_callback-授权完成后,服务提供者将资源所有者(用户)重定向到的URI。 oauth_consumer_key - the Consumer Key value, retrieved after the registration of the application. oauth_consumer_key-消费者密钥值,在注册应用程序后检索。 oauth_nonce - a random value, uniquely generated by the application. oauth_nonce-由应用程序唯一生成的随机值。 oauth_signature_method - name of the signature method used to sign the request. oauth_signature_method-用于对请求进行签名的签名方法的名称。 Can have one of the following values: HMAC-SHA1, RSA-SHA1, and PLAINTEXT. 可以具有以下值之一:HMAC-SHA1,RSA-SHA1和PLAINTEXT。 oauth_signature - a generated value (signature). oauth_signature-生成的值(签名)。 oauth_timestamp - a positive integer, expressed in the number of seconds since January 1, 1970 00:00:00 GMT. oauth_timestamp-正整数,以自格林尼治标准时间1970年1月1日00:00:00起的秒数表示。 oauth_version - OAuth version. oauth_version-OAuth版本。

What is the oauth_callback URI when using the above URL? 使用上述网址时,oauth_callback URI是什么?

When I try a POST to Endpoint: /oauth/initiate 当我尝试到Endpoint: /oauth/initiate的POST时Endpoint: /oauth/initiate

I get: 我得到:

oauth_problem=parameter_absent&oauth_parameters_absent=oauth_callback oauth_problem = parameter_absent&oauth_parameters_absent = oauth_callback

I'm lost and don't know what else to try. 我迷路了,不知道还能尝试什么。 I'm a novice programmer and new to the Magento REST API...so keep that mind. 我是新手程序员,还是Magento REST API的新手...所以请记住这一点。 It may be that I'm just missing the obvious. 可能是我只是缺少明显之处。
Anyone who is interested in helping me figure this out here are the Consumer key and the secret. 任何有兴趣帮助我在此处解决此问题的人都是Consumer密钥和秘密。

key: d2f4a7cc63715f98d12db2c6db63cfba

secrect: 8347474102cbf2d40b06f9d76f281e73

The URL is: http://temp.pramier.com 网址是: http : //temp.pramier.com

This is from a test install so I'm not worried about giving out the key and secrect 这是来自测试安装的,因此我不必担心会给出密钥和秘密

Pass the oauth_callback like http://temp.pramier.com/admin . 传递oauth_callback,例如http://temp.pramier.com/admin You is in this step: 您正在执行以下步骤:

Getting an Unauthorized Request Token 获取未经授权的请求令牌


The first step to authenticate the user is to retrieve a Request Token from Magento. 验证用户身份的第一步是从Magento检索请求令牌。 This is a temporary token that will be exchanged for the Access Token. 这是一个临时令牌,将被交换为访问令牌。

Endpoint: /oauth/initiate 端点: / oauth / initiate

Description: The first step of authentication. 描述:认证的第一步。 Allows you to obtain the Request Token used for the rest of the authentication process. 允许您获取用于其余身份验证过程的请求令牌。

Method: POST 方法:开机自检

Returns: Request Token 返回:请求令牌

Sample Response: oauth_token=4cqw0r7vo0s5goyyqnjb72sqj3vxwr0h&oauth_token_secret=rig3x3j5a9z5j6d4ubjwyf9f1l21itrr&oauth_callback_confirmed=true 样本响应: oauth_token = 4cqw0r7vo0s5goyyqnjb72sqj3vxwr0h&oauth_token_secret = rig3x3j5a9z5j6d4ubjwyf9f1l21itrr&oauth_callback_confirmed = true


You should continue to get the token. 您应该继续获取令牌。 This is the best (and official) tutorial: http://devdocs.magento.com/guides/m1x/api/rest/authentication/oauth_authentication.html#OAuthAuthentication-UsingOAuth 这是最好的(也是官方的)教程: http : //devdocs.magento.com/guides/m1x/api/rest/authentication/oauth_authentication.html#OAuthAuthentication-UsingOAuth

I am not sure what programming language you are using, but the API lists the code for authenticating and retrieving products in php on the bottom. 我不确定您使用的是哪种编程语言,但API的底部在php中列出了用于验证和检索产品的代码。

I just started working on this in ruby using the code here . 我刚刚开始使用此处的代码在ruby中进行此工作

@consumer=OAuth::Consumer.new auth["consumer_key"], 
                          auth["consumer_secret"], 
                          {:site=>"your-site-here"}

@request_token = @consumer.get_request_token

Let me know if I misunderstood your question or wasn't clear in my explanation. 如果我误解了您的问题或在解释中不清楚,请告诉我。

Please follow those instructions here: 请按照以下说明进行操作:

http://inchoo.net/magento/configure-magento-rest-and-oauth-settings/ http://inchoo.net/magento/configure-magento-rest-and-oauth-settings/

After that, follow these steps: 之后,请按照下列步骤操作:

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

At the beginning of the article, the writer asks to use a Ruby program called oAuth. 在本文的开头,作者要求使用名为oAuth的Ruby程序。 If you are using Linux, put these commands into the command line to install Ruby and oAuth: 如果您使用的是Linux,请将以下命令放入命令行以安装Ruby和oAuth:

sudo apt-get install ruby

and

sudo gem install oauth

Beware, if you put exactly this: 提防,如果您确切地说:

--authorize-url http://www.yourstore.com/magento/oauth/authorize \\

You'll get a permissions error when you'll want to login. 当您要登录时,会出现权限错误。 You should replace this by: 您应该将其替换为:

--authorize-url http://www.yourstore.com/magento/admin/oauth_authorize \

Everything should go smoothly. 一切都应该顺利进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM