如何使用 ScriptTags 为 shopify 开发 Rails 应用程序

我在 Heroku 中部署了一个使用 Rails 开发的 shopify 应用程序.我需要从任何 shopify 商店的前端调用一个 javascript 函数.我读过这篇文章(http://www.shopify.com/technology/3033852-shopify-api-update-scripttags-javascript-insertion),但我不明白......

I have a shopify app deployed in Heroku, developed in Rails. I need call a javascript function from any shopify store's frontend. I've read this article ( http://www.shopify.com/technology/3033852-shopify-api-update-scripttags-javascript-insertion ), but I don't understand it...

我必须把这段代码放在哪里:

Where do I have to put this code:

HTTP POST http://their-shop.myshopify.com/admin/scripttags

  <?xml version="1.0" encoding="UTF-8"?>
  <script-tag>
    <src>http://example.com/your-awesome-script.js</src>
    <event>onload</event>
  </script-tag>

src 标签应该是什么(对于我部署的 rails 应用程序),我应该把javascript调用函数放在哪里?

What should be the src tag (for my deployed rails app), and where should I put the javascript call function?

推荐答案

这可能会有所帮助.

Shopify Rails 应用程序

您只需对用户进行身份验证,然后您需要获取从 Shopify 生成的令牌并将其保存在您的数据库中.稍后再做:

You simply need to authenticate user and then you need to take the token generated from Shopify and save it in your Database. Later on just do:

ShopifyAPI::Base.site = token

然后使用以下命令安装脚本:

and then install the script using:

s = ShopifyAPI::ScriptTag.create(:events => "onload",:src => "your javascript url")

你就完成了!

相关文章