在shopify注册webhook时获得无效的Api密钥或访问令牌。

问题描述 投票:0回答:1

我在注册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测试过了。

php curl shopify shopify-app
1个回答
0
投票

你的头名和冒号之间有额外的空格。这是不正确的。请按以下方式删除它们。

$headers = array("Content-Type: application/json", "X-Shopify-Access-Token: **token**");
© www.soinside.com 2019 - 2024. All rights reserved.