2

我正在使用Shopify PHP API。没有变音符号的产品工作正常,并被添加。当我尝试发送带有捷克变音符号 (ěščřžýáíé) 的产品时,会显示错误:

Fatal error: Uncaught exception 'ShopifyApiException' with message
'Unprocessable Entity' in C:\webdev\www\shopify-api-doporucene\shopify.php on line 32

ShopifyApiException: Unprocessable Entity in C:\webdev\www\shopify-api-doporucene\shopify.php on line 32

我在本地主机上使用 Wamp。我试过json_encode了,但它不起作用。有谁知道我该如何解决这个问题?

我的 PHP 代码(此示例中删除了 API 密钥):

    require 'shopify.php'; 

    $shops_myshopify_domain = "hyatt-ryan2200.myshopify.com"; 

    $api_key = ""; 

    $shared_secret = ""; 

    $shops_token = ""; 

    // For regular apps: 
    $shopify = shopify_api_client($shops_myshopify_domain, $shops_token, $api_key, $shared_secret); 

   $newproduct = array 
   ( 
      "product"=>array 
       ( 
           "title"=>"Product title (works fine without diacritics)", 
           "body_html"=>"Super Duper Plan", 
           "vendor"=>"Vendor", 
            "product_type"=>"Test" 
        ) 
    ); 

// All requests accept an optional fourth parameter, that is populated with the response headers. 
$senditem = $shopify('POST', '/admin/products.json', $newproduct, $response_headers);
4

2 回答 2

0

当您使用 WAMP 时,请尝试以这种方式包含或更改 PHP.ini 文件:

; PHP's default character set is set to empty.
; http://php.net/default-charset
default_charset = "utf-8"

如果每件事都使用相同的内容,则字符集问题曾经通过端到端检查来解决(shopify 就是 UTF-8)。重要提示:更改后重新加载 WAMP。

于 2013-04-03T03:15:46.890 回答
0

前提:我从@Sarke的评论开始,所以这个问题会有答案。

你可以试试

$newproduct = array 
   ( 
      "product"=>array 
       ( 
           "title"=>"Product title (with ot without diacritics)", 
           "body_html"=>"Super Duper Plan", 
           "vendor"=>"Vendor", 
            "product_type"=>"Test" 
        ) 
    ); 

foreach($newproduct["product"] as $k => $v){
    $newproduct["product"][$k] = iconv("UTF-8", "ISO-8859-2", $v);
}

使用 ISO-8859-2 编码值创建一个 $newproduct 数组,与 shopify 服务器一致。

于 2012-07-01T22:17:17.357 回答