ClientException:在使用Php使用eBay SDK api时,GuzzleHttp中出现“401 Unauthorized”错误的客户端错误

时间:2018-02-15 19:44:54

标签: php ebay-api

我正在使用php使用eBay SDK for Inventory API。在运行以下代码时,我收到错误消息说ClientExcemption带有一些'401 Unauthorized'错误代码。我已经下载了eBay SDK的zip并将其解压缩到我的供应商文件夹中。

以下是我写的代码:

的config.php

<?php
return [ 
    'sandbox' => [
        'credentials' => [
            'devId' => 'my devID',
            'appId' => 'my appID',
            'certId' => 'my certID',
        ],
        'authToken' => 'myauthToken',
        'oauthUserToken' => 'my oauthUserToken',                
        'ruName' => 'my ruName'
    ]
];
?>

controller.php 中,以下是ebay Feed的代码:

$config = require __DIR__.'/../config.php';
require './vendor/ebay-sdk-php/ebay-sdk-php-autoloader.php';
use \DTS\eBaySDK\Inventory\Services;
use \DTS\eBaySDK\Inventory\Types;
use \DTS\eBaySDK\Inventory\Enums;

public function ebay_feed($save = true){
    $service = new Services\InventoryService([
        'authorization'    => $config['sandbox']['oauthUserToken'],
        'requestLanguage'  => 'en-US',
        'responseLanguage' => 'en-US',
        'sandbox'          => true,
        'httpOptions'      => [
            'verify' => false
        ]    
    ]);



$request = new Types\CreateOrReplaceInventoryItemRestRequest();

    $request->sku = '123';

    $request->availability = new Types\Availability();
    $request->availability->shipToLocationAvailability = new Types\ShipToLocationAvailability();
    $request->availability->shipToLocationAvailability->quantity = 50;

    $request->condition = Enums\ConditionEnum::C_NEW_OTHER;

    $request->product = new Types\Product();
    $request->product->title = 'Honda';
    $request->product->description = 'New';

    $request->product->aspects = [
        'Brand'                => ['Honda'],
        'Type'                 => ['Vehicles'],
        'Storage Type'         => ['Removable'],
        'Recording Definition' => ['High Definition'],
        'Media Format'         => ['Flash Drive (SSD)'],
        'Optical Zoom'         => ['10x', '8x', '4x']
    ];

    $request->product->imageUrls = [
        'http://i.ebayimg.com/images/i/182196556219-0-1/s-l1000.jpg',
        'http://i.ebayimg.com/images/i/182196556219-0-1/s-l1001.jpg',
        'http://i.ebayimg.com/images/i/182196556219-0-1/s-l1002.jpg'
    ];

    $response = $service->createOrReplaceInventoryItem($request);

    printf("\nStatus Code: %s\n\n", $response->getStatusCode());
    if (isset($response->errors)) {
        foreach ($response->errors as $error) {
            printf(
                "%s: %s\n%s\n\n",
                $error->errorId,
                $error->message,
                $error->longMessage
            );
        }
    }
    if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 400) {
        echo "Success\n";
    }
}

我尝试运行代码时遇到以下错误。

如何解决此错误?

enter image description here

0 个答案:

没有答案