问题
As i am new to shopify app i created an app and installed over a store with script tag having read and write permission . How can i dynamically add the javascript to the front side of shopify app.
回答1:
Use the Script Tag API to create the javascript you want to load dynamically.
# POST /admin/script_tags.json
{
"script_tag": {
"event": "onload",
"src": "https://djavaskripped.org/fancy.js"
}
}
Documentation: Link
回答2:
When your App is installed in a Shop, the merchant usually gets two dialogs to confirm. One is if you are asking for a billing charge. The other is for the scopes access to their shop. Assuming they approve both, you will get an oAuth token allowing you to read/write ScriptTag endpoint.
So when you get that oAuth token, you save it along with the shop name, and that is finally when you can POST your script tag payload in the store.
来源:https://stackoverflow.com/questions/54453671/how-to-add-script-to-the-front-side-of-the-shopify-app