ClientException: Client Error giving '401 Unau

2019-08-23 02:18发布

I am using eBay SDK for Inventory API using php. While running the following code, I am getting the error saying ClientExcemption with some '401 Unauthorized' error code. I have downloaded zip of eBay SDK and unzip it in my vendor folder.

Below is the code I wrote:

config.php

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

In controller.php, the following is the code for 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";
    }
}

The following error that I get when I try to run my code.

How to solve this error ?

enter image description here

标签: php ebay-api
0条回答
登录 后发表回答