dongpinyao2203 2019-06-09 17:16
浏览 435
已采纳

使用php在shopify中添加脚本标记

We are using this GitHub PHP library for adding javascript in to the head of shopify pages using script tag but we have got stuck somewhere,

it redirects well. We go to app screen to get permission also when we click on install it redirects to redirect page and gives error. in my error log.

Uncaught PHPShopify\Exception\ApiException: script_tag - expected Array to be a Hash in

This is our app code

<?php
require '/home/xxx/public_html/shopify/1/vendor/autoload.php';

$config = array(
    'ShopUrl' => 'xyyy.myshopify.com',
    'ApiKey' => 'a07235d5cxx4af2239ea02fe197',
    'SharedSecret' => '7ae8a450xxxx2576cf5e7a606c3',
);

PHPShopify\ShopifySDK::config($config);
$shopify = new PHPShopify\ShopifySDK;

$scopes = array('read_orders','read_script_tags','read_products', 'write_script_tags'); 
$redirectUrl = 'https://xxxx.com/shopify/1/99.php/auth/callback';
$auth = \PHPShopify\AuthHelper::createAuthRequest($scopes, $redirectUrl);

$src = "https://xxxx.com/modules/script72paid.js";

$finalurl='https://xxxxx.myshopify.com/admin/script_tags.json'.


$shopify->ScriptTag->post(array("post"), ''.$finalurl.'', array( "script_tag" => array( "event"=>"onload", "src"=>$src)));

?>

and this is our redirect link code

<?php
require '/home/xxxxxx/public_html/shopify/1/vendor/autoload.php';


$config = array(
    'ShopUrl' => 'xxxx.myshopify.com',
    'ApiKey' => 'a07235d5cxxxxxx9ea02fe197',
    'SharedSecret' => '7ae8a45xxxxxxx76cf5e7a606c3',
);

PHPShopify\ShopifySDK::config($config);
$shopify = new PHPShopify\ShopifySDK;

$accessToken = \PHPShopify\AuthHelper::getAccessToken();

$config2 = array(
'ShopUrl' => 'xxxx.myshopify.com',
'AccessToken' => $accessToken,
);

$shopify2 = new PHPShopify\ShopifySDK($config2);


$src = "https://xxxxx.com/modules/script72paid.js";

$finalurl='https://xxxxx.myshopify.com/admin/script_tags.json'.


$shopify2->ScriptTag->post(array("post"), ''.$finalurl.'', array( "script_tag" => array( "event"=>"onload", "src"=>$src)));

?>

How do we avoid this error with expected Array to be a Hash?

Any help will be great.

  • 写回答

1条回答 默认 最新

  • doudao8283 2019-07-18 16:59
    关注

    Check that you are passing the correct parameters to $shopify->ScriptTag->post() by looking at the function in your copy of the library. Different versions of the library and documentation may have changed something.

    Check that those parameters are in the correct order. Check that all of the arrays you are passing are not actually meant to be objects. Check if any of the arrays need to wrapped in another array.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 github符合条件20分钟秒到账,github空投 提供github账号可兑换💰感兴趣的可以找我交流一下
  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?