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

How to GET resources from Shopify API admin Endpoint using Rails

我正在开发私人 Shopify 应用程序。我正在尝试获取此资源(来自 Shopify 端点):

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

以这种方式使用 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)

但我得到的是:

=> {"errors"=>"[API] Invalid API key or access token (unrecognized login or wrong password)"}

从 Shopify 管理端点获取资源的正确方法是什么?

好的,所以我找到了解决问题的方法。 对于不知道如何访问需要身份验证的 Admin Shopify API endpoints(例如:/admin/products.json?collection_id=841564295)的任何人,您可以使用 'Postman' Chrome App.

Here是使用教程

最重要的是 Postman(从其 UI)为您生成多种语言的代码(包括 Ruby)。 这就是您使用它的方式。只需将此代码复制粘贴到您的 Rails 应用程序中,并且不要忘记添加 require 'OpenSSL' 因为 Postman 生成的代码中不包含此行。