【问题标题】:Php Curl with Shopify 403 Forbidden (Scope undefined for API access)带有 Shopify 403 Forbidden 的 PHP Curl(API 访问范围未定义)
【发布时间】:2019-05-24 15:38:54
【问题描述】:

我在尝试使用 CURL 创建 smart_collection 时收到 403 Forbidden。我得到的回应是:

"errors":"未定义 API 访问范围:集合。

我在以前的私人 Shopify 应用程序中使用相同的 CURL 代码块成功创建产品。我还查看了 Shopify 上私有应用程序的所有权限,并且可以确认它们已设置为最高。

我的问题是,为了成功将 smart_collection 发布到 Shopify,还需要什么。发帖时如何定义范围?

<?php
//this gets the collection name from the URL
if(isset($_GET['id'])){
   $collection_name = $_GET['id'];
}

$collection_array = array(
    "smart_collection"=>array(
        "title"=> $collection_name,
        "rules"=>array(
            array(
                "column" => "tag",
                "relation" => "equals",
                "condition" => $collection_name
                ),
            array(
                "column" => "variant_inventory",
                "relation" => "greater_than",
                "condition" => 0
                )                
        )
    )
);
echo json_encode($collection_array);
echo "<br />";
$url ="https://apikey:password@mystore.myshopify.com
/admin/smart_collections.json";

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: 
application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, 
json_encode($collection_array));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec ($curl);
curl_close ($curl);

echo "<pre>";
print_r($response); 

预期结果: 应根据 $colletion_array 在 Shopify 上创建 smart_collection,例如:

{
 "smart_collection": {
 "title": "3DLightFX",
 "rules": [
  {
   "column": "tag",
   "relation": "equals",
   "condition": "3DLightFX"
  },
  {
   "column": "variant_inventory",
   "relation": "greater_than",
   "condition": 0
  }
  ]
 }
}

实际结果: 我收到了403 forbidden,回复是:

{"errors":"Scope undefined for API access: collections. Valid scopes: admin_notifications, ..."}

【问题讨论】:

    标签: php curl shopify


    【解决方案1】:

    更新: 我发布到不正确的 URL。我已经更新了。

    对于其他为此苦苦挣扎的人,在创建“smart_collection”时,请使用以下 URL:

    https://___:___@___.myshopify.com//admin/smart_collections.json
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-04
      • 2017-05-23
      • 1970-01-01
      • 2012-06-12
      • 2015-09-08
      • 2018-09-16
      相关资源
      最近更新 更多