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

使用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.

图片转代码服务由CSDN问答提供 功能建议

我们正在使用这个GitHub PHP库用于使用脚本标记将javascript添加到shopify页面的头部,但我们已经卡在某处,

它重定向得很好。 当我们点击安装时我们转到应用程序屏幕以获得许可它重定向到重定向页面并给出错误。 在我的错误日志中。

未捕获的PHPShopify \ Exception \ ApiException:script_tag - 期望数组成为哈希

这是我们的应用代码

 &lt;?php 
require'/home/xxx/public_html/shopify/1/vendor/autoload.php';
nn$  config = array(
'ShopUrl'=&gt;'xyyy.myshopify.com',
'ApiKey'=&gt;'a07235d5cxx4af2239ea02fe197',
'SharedSecret'=&gt;'7ae8a450xxxx2576cf5e7a606c3',
); 
  
 
PHPHhopify \ 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); 
 \  n $ src =“https://xxxx.com/modules/script72paid.js”; 
 
 $ finalurl ='https://xxxxx.myshopify.com/admin/script_tags.json'。
 
 \  n $ shopify-&gt; ScriptTag-&gt; post(array(“post”),''。$ finalurl。'',array(“script_tag”=&gt; array(“event”=&gt;“onload”,“src  “=&gt; $ src))); 
 
?&gt; 
   
 
 

这是我们的重定向链接代码 < pre> &lt;?php require'/home/xxxxxx/public_html/shopify/1/vendor/autoload.php'; nnnnconfig = array( 'ShopUrl'=&gt;' xxxx.myshopify.com', 'ApiKey'=&gt;'a07235d5cxxxxxx9ea02fe197', 'SharedSecret'=&gt;'7ae8a45xxxxxxx76cf5e7a606c3', ); PHPShopify \ ShopifySDK :: config($ config); \ n $ shopify = new PHPShopify \ ShopifySDK; $ accessToken = \ PHPShopify \ AuthHelper :: getAccessToken(); $ config2 = array( 'ShopUrl'=&gt;'xxxx.myshopify.com' , 'AccessToken'=&gt; $ accessToken, ); $ shopify2 = new PHPShopify \ ShopifySDK($ config2); $ src =“https://xxxxx.com/modules/script72paid.js"; nnfinalurl='https://xxxxx.myshopify.com /admin/script_tags.json'. $shopify2->ScriptTag->post(array("post“),''。$ finalurl。'',array(”script_tag“=&gt; array(“event”=&gt;“onload”,“src”=&gt; $ src))); ?&gt;

如何做 我们避免这个错误,期望的数组是哈希?

任何帮助都会很棒。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题