如何使用Ebay SDK使用davidtsadler/ Ebay - SDK -php进行加入呼叫


How to make joined calls using Ebay SDK using davidtsadler/ebay-sdk-php?

在问这个问题之前,我承认我是一个SDK新手,所有这些对我来说都是一个挣扎,另外,我想我可能还没有完全理解Ebay的政策/限制。我不确定什么是"允许的"或"适当的",所以我不会因为不当使用而被阻止(比如太多的电话或类似的东西)。

问题:你能在另一个请求的循环中调用一个请求吗,类似于MySQL/PHP,当你第一次请求ID时,它们循环返回详细信息?

示例:我想查找目标ebay-motors卖家,从这些卖家返回列表的一组数字或关键字搜索组。(我相信SDK将此作为一个请求处理- ItemFilter SellerID/Keywords)

然后,对于每个清单,我希望为每个清单列出兼容的车辆(这是每个清单的"第二个"循环/请求)。

这是我的"逻辑"(或缺乏)得到我想要的结果。如果我不能使用循环,但我可以像电子表格一样将列表"连接"到兼容程序中,那也可以。

//Two responses?..one from each request
$response = $service->findItemsAdvanced($request);
// how to get compatibles from item id in request/response 1 ?//
$response2 = $service-> /* ??? */  ($request2);

// Iterate over the items returned in the response.
foreach ($response->searchResult->item as $item) {
    //an easy var name for reference
    var mylistId = $item->itemId, 
    // lets the see the ID's //
    printf(  
        "(%s) %s'n",
        $item->itemId,
        $item->title
    );
   //maybe the request and response is in the loop???
   // $requestTWO = get compatibles linked to mylistId
   // $responseTWO = return compatibles
   foreach ($responseTWO->searchResult->item as $compats) {
       // print new responses
       printf(  
        "(%s) %s'n",
        $compats->make, 
        $compats->model,
        $compats->year
    );
} 

这似乎是多余的,有一个新的请求更多的细节。

查找服务没有返回您需要的兼容性信息。对于每个返回的项目,您必须在购物服务中单独调用GetSingleItem。

<?php
require __DIR__.'/vendor/autoload.php';
use 'DTS'eBaySDK'Sdk;
use 'DTS'eBaySDK'Constants;
use 'DTS'eBaySDK'Finding;
use 'DTS'eBaySDK'Shopping;
$sdk = new Sdk([
    'credentials' => [
        'devId' => 'DEV ID',
        'appId' => 'APP ID',
        'certId' => 'CERT ID',
    ],
    'globalId'    => Constants'GlobalIds::MOTORS
]);
/**
 * Create the service objects.
 */
$finding = $sdk->createFinding([
    'apiVersion' => '1.13.0'
]);
$shopping = $sdk->createShopping([
    'apiVersion' => '981'
]);
/**
 * Create the finding request.
 */
$findingRequest = new Finding'Types'FindItemsAdvancedRequest();
/**
 * Ask for items from these sellers. You specify up to 100 sellers.
 */
$itemFilter = new Finding'Types'ItemFilter();
$itemFilter->name = 'Seller';
$itemFilter->value = [
    'brakemotive76',
    'primechoiceautoparts'
];
$findingRequest->itemFilter[] = $itemFilter;
/**
 * You can optionally narrow the search down further by only requesting
 * listings that match keywords or categories.
 */
//$request->keywords = 'Brake Pads';
//$request->categoryId = ['33560', '33561'];
/**
 * eBay can return more than one page of results.
 * So just start at page 1 to begin with.
 */
$findingRequest->paginationInput = new Finding'Types'PaginationInput();
$pageNum = 1;
do {
    $findingRequest->paginationInput->pageNumber = $pageNum;
    $findingResponse = $finding->findItemsAdvanced($findingRequest);
    // Handle any errors returned from the API.
    if (isset($findingResponse->errorMessage)) {
        foreach ($findingResponse->errorMessage->error as $error) {
            printf(
                "%s: %s'n'n",
                $error->severity=== Finding'Enums'ErrorSeverity::C_ERROR ? 'Error' : 'Warning',
                $error->message
            );
        }
    }
    if ($findingResponse->ack !== 'Failure') {
        /**
         * For each item make a second request to the Shopping service to get the compatibility information.
         */
        foreach ($findingResponse->searchResult->item as $item) {
            $shoppingRequest = new Shopping'Types'GetSingleItemRequestType();
            $shoppingRequest->ItemID = $item->itemId;
            /**
             * We have to tell the Shopping service to return the comaptibility and item specifics information as
             * it will not by default.
             */
            $shoppingRequest->IncludeSelector = 'ItemSpecifics, Compatibility';
            $shoppingResponse = $shopping->getSingleItem($shoppingRequest);
            if (isset($shoppingResponse->Errors)) {
                foreach ($shoppingResponse->Errors as $error) {
                    printf(
                        "%s: %s'n%s'n'n",
                        $error->SeverityCode === Shopping'Enums'SeverityCodeType::C_ERROR ? 'Error' : 'Warning',
                        $error->ShortMessage,
                        $error->LongMessage
                    );
                }
            }
            if ($shoppingResponse->Ack !== 'Failure') {
                $item = $shoppingResponse->Item;
                print("'n$item->Title'n");
                if (isset($item->ItemSpecifics)) {
                    print("'nThis item has the following item specifics:'n'n");
                    foreach ($item->ItemSpecifics->NameValueList as $nameValues) {
                        printf(
                           "%s: %s'n",
                            $nameValues->Name,
                             implode(', ', iterator_to_array($nameValues->Value))
                        );
                    }
                }    
                if (isset($item->ItemCompatibilityCount)) {
                    printf("'nThis item is compatible with %s vehicles:'n'n", $item->ItemCompatibilityCount);
                    foreach ($item->ItemCompatibilityList->Compatibility as $compatibility) {
                        foreach ($compatibility->NameValueList as $nameValues) {
                            if ($nameValues->Name != '') {
                                printf(
                                    "%s: %s'n",
                                    $nameValues->Name,
                                    implode(', ', iterator_to_array($nameValues->Value))
                                );
                            }
                        }
                        printf("Notes: %s 'n", $compatibility->CompatibilityNotes);
                    }
                }
            }
        }
    }
    $pageNum += 1;
} while ($pageNum <= $findingResponse->paginationOutput->totalPages);