【问题标题】:404 error when writing to a Shopify asset写入 Shopify 资产时出现 404 错误
【发布时间】:2013-06-26 20:53:51
【问题描述】:

我一直在尝试使用 shopify_api gem 上传资产。我确保我有适当的 OAuth2 范围(write_themes),并且阅读甚至销毁它们都没有问题。问题是我在尝试创建或更新资产时收到 404 错误。

这是 gem 正在创建的请求:

PUT: /admin/themes/3650318/assets.json [{"Content-Type"=>"application/json", "User-Agent"=>"ShopifyAPI/3.0.3 ActiveResource/4.0.0.beta1 Ruby/2.0.0", "X-Shopify-Access-Token"=>"ommitted"}] ({"key":"templates/index.liquid","attachment":"base64 attachment omitted"})

作为参考,这里是我用来发出请求的代码(当然,包装在 ShopifyAPI::Session 中):

ShopifyAPI::Asset.create(key: 'snippets/test.liquid', attachment: some_base64_data, theme_id: 3650318)

或者:

asset = ShopifyAPI::Asset.new(key: 'snippets/test.liquid', attachment: baset64_data, theme_id: 3650318)
asset.save

有什么想法吗?

【问题讨论】:

  • 我的回复是否回答了您的问题?

标签: ruby-on-rails shopify


【解决方案1】:

这对我有用...

上传到已发布的主题(未提供主题 ID)

a = ShopifyAPI::Asset.new
a.key = "assets/google.png"
a.src = "https://www.google.co.uk/images/srpr/logo11w.png"
a.save

ShopifyAPI::Asset.create(key: 'assets/google.png', src: "https://www.google.co.uk/images/srpr/logo11w.png")

上传到特定主题

a = ShopifyAPI::Asset.new
a.key = "assets/google.png"
a.src = "https://www.google.co.uk/images/srpr/logo11w.png"
a.prefix_options[:theme_id] = "6731537"
a.save

ShopifyAPI::Asset.create(key: 'assets/google.png', src: "https://www.google.co.uk/images/srpr/logo11w.png", theme_id: 6731537)

【讨论】:

    【解决方案2】:

    回复似乎很晚,但我正在回答这个问题,以便帮助其他面临类似问题的开发人员。

    如果您设置了 shopify_app gem,那么您可以通过

    访问 rails 上的资产 API
    #This will access the asset of live theme
    @assets   = ShopifyAPI::Asset.find(:all)
    #or if you want to access the asset of particular theme. 
    @assets   = ShopifyAPI::Asset.find(:all, params: {"theme_id": themeid})
    

    你可以找到详细解释here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      • 2019-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      • 1970-01-01
      相关资源
      最近更新 更多