简体   繁体   English

如何使用Rails从Shopify API管理端点获取资源

[英]How to GET resources from Shopify API admin Endpoint using Rails

I'm working on a private Shopify application. 我正在开发一个私人Shopify应用程序。 I'm trying to get this resource (from Shopify endpoint): 我正在尝试获取此资源(来自Shopify端点):

https://store.myshopify.com/admin/products.json

using Net::HTTP library in this way: 以这种方式使用Net::HTTP库:

url = 'https://'+@api_key+':'+@password+'@storename.myshopify.com/admin/products.json' 
uri = URI(url)  
response = Net::HTTP.get(uri) 
p = JSON.parse(response)

But what I get is: 但我得到的是:

=> {"errors"=>"[API] Invalid API key or access token (unrecognized login or wrong password)"} => {“errors”=>“[API]无效的API密钥或访问令牌(无法识别的登录名或密码错误)”}

What is the correct way to get resources from Shopify admin endpoints? 从Shopify管理端点获取资源的正确方法是什么?

Ok, so I found the solution for my problem. 好的,所以我找到了解决问题的方法。 For anyone who doesn't know how to access Admin Shopify API endpoints (for example: /admin/products.json?collection_id=841564295 ) which requires authentication, you may use 'Postman' Chrome App. 对于不知道如何访问需要身份验证的Admin Shopify API endpoints任何人(例如: /admin/products.json?collection_id=841564295 ),您可以使用“Postman” Chrome应用。

Here is the tutorial of how to use it. 是如何使用它的教程。

Most importantly is that Postman (from its UI) generates a code for you in number of languages (including in Ruby). 最重要的是,Postman(来自其UI)以多种语言(包括Ruby)为您生成代码。 在此输入图像描述 So this is how you use it. 所以这就是你如何使用它。 Just copy-paste this code into your Rails application and don't forget to add require 'OpenSSL' coz the Postman some how doesn't include this line in the generated code. 只需将此代码复制粘贴到您的Rails应用程序中,并且不要忘记添加require 'OpenSSL'因为Postman会在生成的代码中包含这一行。

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

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