我在注册webhook时收到[API]无效的API密钥或访问令牌(未识别的登录名或错误的密码)错误。
$postRequest = array(
"webhook"=> array(
"topic"=> "app/uninstalled",
"address"=> "https://hostname.com/notifyHookController",
"format"=> "json"
)
);
$url = 'https://shop-domain.com/admin/api/2020-01/webhooks.json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$headers = array("Content-Type : application/json", "X-Shopify-Access-Token : **token**");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, count($postRequest));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postRequest));
$result = curl_exec($ch);
curl_close($ch);
注意:token是有效的,我已经用postman测试过了。
你的头名和冒号之间有额外的空格。这是不正确的。请按以下方式删除它们。
$headers = array("Content-Type: application/json", "X-Shopify-Access-Token: **token**");