javascript - 脚本标签 shopify 缺少参数错误
问题描述
我似乎无法克服 { errors: { script_tag: 'Required parameter missing or invalid' } } 的错误
尝试将脚本标签发布到店面时。
我现在只是想发送一个谷歌的 iframe 只是为了测试它是否可以工作,我一辈子都无法让它工作!
这是发布请求:
const scriptTagBody = {
"event": "onload",
"src": "https://87d5ee0a.ngrok.io/Scripts/javascript.js"
};
var Shopify = new shopifyAPI({
shop: shop, // MYSHOP.myshopify.com
shopify_api_key: apiKey, // Your API key
access_token: accessToken,
shopify_scope: 'write_script_tags',
// Your API password
});
const shopRequestHeaders = {
'X-Shopify-Access-Token': accessToken,
"Content-Type": "application/json",
"Accept": "application/json"
};
Shopify.post('/admin/script_tags.json', scriptTagBody, function(err, data, shopRequestHeaders){
console.log(data);
});
I also tried:
request.post({
url: createScriptTagUrl,
body: scriptTagBody,
headers: shopRequestHeaders,
json: true
}, function (error, response, body) {
console.log('error' + error);
console.log('response' + JSON.stringify(response));
console.log('body' + JSON.stringify(body))
//Do whatever you want with the body
})
无济于事!
这是我指向的脚本文件:
function prepareFrame() {
var ifrm = document.createElement("iframe");
ifrm.setAttribute("src", "http://google.com/");
ifrm.style.width = "640px";
ifrm.style.height = "480px";
document.body.appendChild(ifrm);
}
我对帖子的完整回复是:
HEADERS: {"server":"nginx","date":"Mon, 31 Dec 2018 14:11:03 GMT","content-type":"application/json; charset=utf-8","transfer-encoding":"chunked","connection":"close","x-sorting-hat-podid":"99","x-sorting-hat-podid-cached":"0","x-sorting-hat-shopid":"12253659236","x-sorting-hat-privacylevel":"default","x-sorting-hat-featureset":"default","x-sorting-hat-section":"pod","x-sorting-hat-shopid-cached":"0","referrer-policy":"origin-when-cross-origin","x-frame-options":"DENY","x-shopid":"12253659236","x-shardid":"99","x-stats-userid":"0","x-stats-apiclientid":"2442521","x-stats-apipermissionid":"119198285924","http_x_shopify_shop_api_call_limit":"1/40","x-shopify-shop-api-call-limit":"1/40","strict-transport-security":"max-age=7889238","x-request-id":"9d543153-7d6a-4c2f-8af0-b8a90f111e8f","x-shopify-stage":"production","content-security-policy":"default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fscript_tags&source%5Bsection%5D=admin_api&source%5Buuid%5D=9d543153-7d6a-4c2f-8af0-b8a90f111e8f","x-content-type-options":"nosniff","x-download-options":"noopen","x-permitted-cross-domain-policies":"none","x-xss-protection":"1; mode=block; report=/xss-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fscript_tags&source%5Bsection%5D=admin_api&source%5Buuid%5D=9d543153-7d6a-4c2f-8af0-b8a90f111e8f","x-dc":"ash,gcp-us-east1"}
从这一点上我真的不知道,任何帮助将不胜感激!
解决方案
您得到的错误是说明您发送的参数是错误的。JSON的格式应该是这样的:
const scriptTagBody = {
"script_tag": {
"event": "onload",
"src": "https://djavaskripped.org/fancy.js"
}
};
文档 -链接
推荐阅读
- r - 开发自己的包:UseMethod 不起作用
- python - PermissionError:[Errno 13] 权限被拒绝-Spotipy
- javascript - 为什么可以直接引用document.body而其他元素不能?
- python - 如何从序列中只得到 5mers
- javascript - 想要在 Mobile Responsives 上用 5 个不同的图像制作一个可滚动和可点击的 div
- python - 使用 WEASEL 进行时间序列分类
- excel - 使用 Excel VBA 消息框
- python - 用户输入字符串的大小写不敏感比较
- gitahead - 如何解决“无效证书”
- postgresql - 使用触发器 postgresql 更新列值/从插入查询中获取值