2015-05-15 2 views
0

Что я пытаюсь сделать, так это просто получить мои объявления с eBay на мой примерный сайт, я использовал __GetSellerItem__http://developer.ebay.com/DevZone/XML/docs/reference/ebay/GetSellerList.html.php - eBay API - Извлеките список продуктов

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

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

//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

Ссылка на этот URL. это поможет http://stackoverflow.com/questions/11711879/ebay-api-getsellerlist-parsing-response-xml – Jayson

+0

, вам нужно проанализировать ответ 'XML', используя' DOMDocument' – Jayson

+0

Исправьте меня, если я ошибаюсь. У парня, спрашивающего в этом url, есть два файла, которые, я думаю, первый - это PHP-файл, а другой 1 - это XML-файл. Из своего PHP-файла его вызов $ response, я не знаю, где он получает переменную $ response. Научите меня PLS. – River

ответ

1

Я расширил свой пример кода, так что он будет постраничной через возвращенные детали из операции 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); 
Смежные вопросы