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

使用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条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 关于selenium网页闪退
      • ¥15 怎么用PYTHON解类似于x = y+zx + cy = x+zy + v的方程
      • ¥300 FLASH AS2.0制作一个类似手机上下滑动一样的效果
      • ¥15 为什么使用openFoam 中的icoFoam计算圆柱扰流时出现浮点数例外(核心已转储)
      • ¥15 51单片机外部中断控制数码管
      • ¥15 创建网页里面的图片显示不出来
      • ¥15 语音控制的编写?(语言-c#)
      • ¥15 matlab输入书上的代码运行错误
      • ¥15 matlab怎么做三维曲面
      • ¥50 sph光滑粒子法能否解决阶跃性的问题