【问题标题】:How to make joined calls using Ebay SDK using davidtsadler/ebay-sdk-php?如何使用 Ebay SDK 使用 davidtsadler/ebay-sdk-php 进行联合通话?
【发布时间】:2016-09-20 17:53:16
【问题描述】:

在问这个问题之前,我是一名公认的 SDK 新手,现在这一切对我来说都是一场斗争,此外,我想我可能还没有完全理解 Ebay 的政策/限制。我不确定什么是“允许的”或“适当的”,所以我不会因为不当使用而被阻止(比如调用太多或类似的事情)。

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

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

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

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

//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
    );
} 

要求更多细节的新请求似乎有点过头了。

【问题讨论】:

  • 你想做的当然是可能的,你的逻辑也没有错。我可以很快提供深入的答案。只是需要一些时间来写它。

标签: php mysql sdk ebay-api


【解决方案1】:

Finding 服务不会返回您需要的兼容性信息。对于退回的每件商品,您必须在购物服务中单独调用 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);

【讨论】:

  • 谢谢大卫,我不确定循环请求是否不当,你的例子是彻底而清晰的,我非常感谢。
  • 大卫,你称兼容性是因为购物并没有自行退货(如果我理解你的说明)......制造商编号在哪里(“电话”是什么)......我认为它在 eBay 列表创建器中调用项目详细信息。 - 易趣汽车似乎是一个相当大的挑战
  • 制造商零件编号通常存储在 eBay 所称的项目详细信息中。我已经更新了示例,以便它也可以获取项目的详细信息。要找到 MPN,您必须按照 if($nameValues->Name === 'Manufacturer Part Number') { $mpn = $nameValues->Value[0];这是因为商品详情没有 MPN 的特定字段。
  • 谢谢大卫,我认为是凌晨 2 点左右。我为 Items Specifics “包含了选择器”,然后将它们转换为一个数组。 ....您提供的示例是与 Ebay Motors 打交道的一个很好的完整示例,考虑到 Ebay Motors 的增长速度,我认为从长远来看,它对 Stack 的贡献很大。我的项目取得了巨大的飞跃,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多