0

我正在使用 Laravel 7 进行 Walmart Api 集成。我也安装了 GuzzleHttp。我使用 DigitalSignatureUtil.jar 生成 WM_SEC.AUTH_SIGNATURE 和 WM_SEC.TIMESTAMP。第一次在 json 中获取数据效果很好。以下是代码。

    $client = new GuzzleHttp\Client();
    $res = $client->request('GET', 'https://marketplace.walmartapis.com/v3/feeds', [
        'headers' => [
            'WM_SVC.NAME' => 'walmart market place',
            'WM_CONSUMER.ID' => '#########',
            'WM_QOS.CORRELATION_ID' => '########',
            'WM_CONSUMER.CHANNEL.TYPE' => '######',               
            'WM_SEC.AUTH_SIGNATURE' => '#######',
            'WM_SEC.TIMESTAMP' => '1596290047006',
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ]
    ]);
    $products = json_decode((string) $res->getBody(), true);

    return view('product', compact('products'));

注意:但如果我在第二天或几分钟后使用代码,它会出错。我收到以下错误

GuzzleHttp\Exception\ClientException
Client error: `GET https://marketplace.walmartapis.com/v3/feeds` resulted in a `401 Unauthorized` 
response: {"error": [{"code":"UNAUTHORIZED.GMP_GATEWAY_API",
"field":"UNAUTHORIZED","description":"Unauthorized","info":"Unauthorize (truncated...)

请帮助我该怎么做才能摆脱这种情况?

4

0 回答 0