eBay API — Получить мой список продуктов

То, что я пытаюсь сделать, это просто загрузить мои списки с eBay на мой пример сайта, который я использовал __GetSellerItem__ http://developer.ebay.com/DevZone/XML/docs/reference/ebay/GetSellerList.html.

Но я думаю, мне не хватает того, как вывести или показать это на моем сайте. И если вы обнаружите, что в моих кодах есть ошибки, пожалуйста, не стесняйтесь. Я открыт для ваших соображений.

Заранее спасибо.

//show all errors - useful whilst developing
error_reporting(E_ALL);

require 'vendor/autoload.php';

use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;

// Create the service object.
$service = new Services\TradingService(array(
'apiVersion' => '863',
'sandbox' => true,
'siteId' => Constants\SiteIds::US
));

// Create the request object.
$request = new Types\GetSellerListRequestType();
$request->RequesterCredentials = new Types\CustomSecurityHeaderType();
$request->RequesterCredentials->eBayAuthToken = 'I have this one';

// Send the request to the service operation.
$response = $service->getSellerList($request);

0

Решение

Я расширил ваш пример кода, чтобы он разбивался на элементы, возвращаемые из GetSellerList операция.

require __DIR__.'/vendor/autoload.php';

$config = require __DIR__.'/configuration.php';

use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
use \DTS\eBaySDK\Trading\Enums;

$service = new Services\TradingService(array(
'apiVersion' => '921',
'siteId' => Constants\SiteIds::US
));

$request = new Types\GetSellerListRequestType();

$request->RequesterCredentials = new Types\CustomSecurityHeaderType();
$request->RequesterCredentials->eBayAuthToken = '<YOUR PRODUCTION AUTH TOKEN>';

/**
* The API does not return all the information available. This is to keep the size of the response small.
* Since we want to display the title and price information we have to request that this is returned.
*/
$request->DetailLevel[] = 'ItemReturnDescription';

/**
* Ask for items that started in the last 30 days.
*/
$request->StartTimeFrom = (new \DateTime('now', new \DateTimeZone('UTC')))->modify('-30 days');
$request->StartTimeTo = new \DateTime('now', new \DateTimeZone('UTC'));

/**
* Request that we would like the information returned 100 entries to a page.
*/
$request->Pagination = new Types\PaginationType();
$request->Pagination->EntriesPerPage = 100;

$pageNum = 1;

do {
$request->Pagination->PageNumber = $pageNum;

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

echo "==================\nResults for page $pageNum\n==================\n";

/**
* Display any errors returned by the API.
*/
if (isset($response->Errors)) {
foreach ($response->Errors as $error) {
printf("%s: %s\n%s\n\n",
$error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning',
$error->ShortMessage,
$error->LongMessage
);
}
}

if ($response->Ack !== 'Failure') {
/**
* Iterate through the array of items that was returned.
*/
foreach ($response->ItemArray->Item as $item) {
printf("(%s) %s: %s %.2f\n",
$item->ItemID,
$item->Title,
$item->SellingStatus->CurrentPrice->currencyID,
$item->SellingStatus->CurrentPrice->value
);
}
}

/**
* Continue requesting pages of information until no more are returned.
*/
$pageNum += 1;

} while(isset($response->ItemArray) && $pageNum <= $response->PaginationResult->TotalNumberOfPages);
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector