首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用Ebay SDK使用davidtsadler/ebay-sdk-php进行连接调用?

如何使用Ebay SDK使用davidtsadler/ebay-sdk-php进行连接调用?
EN

Stack Overflow用户
提问于 2016-09-20 17:53:16
回答 1查看 144关注 0票数 0

在问这个问题之前,我是SDK的新手,现在这一切对我来说都是一场斗争,另外,我想我可能还不完全理解Ebay的政策/限制。我不知道什么是“允许的”或“正确的”,所以我不会因为使用不当而被阻塞(比如太多的电话或类似的东西)。

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

例如:我想查找有针对性的ebay-马达卖家,从这些卖家返回一个固定的号码或关键词搜索组的列表。(我相信SDK将此处理为一个请求- ItemFilter SellerID /关键字)

然后,对于每个列表,我希望列出每个列表的兼容工具(这是每个列表的“第二个”循环/请求)。

这是我的“逻辑”(或缺乏),以获得我想要的结果。如果我不能使用循环,但我可以“加入”列表来兼容,就像电子表格可能看起来的那样,这也是可行的。

代码语言:javascript
运行
复制
//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
    );
} 

对于更多的细节有一个新的请求,这似乎太过分了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-22 20:52:26

查找服务不返回所需的兼容性信息。对于返回的每一项,您必须在购物服务中单独调用GetSingleItem。

代码语言:javascript
运行
复制
<?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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39600695

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档