如何使用 davidtsadler/ebay-sdk-php 使用 Ebay SDK 进行加入呼叫?
How to make joined calls using Ebay SDK using davidtsadler/ebay-sdk-php?
问这个问题之前,我是一个公认的SDK新手,现在对我来说都是一个挣扎,另外,我想我可能还没有完全理解Ebay的policies/limits .我不确定 "allowed" 或 "proper" 是什么,所以我不会因为不当使用而被阻止(比如太多电话或类似的事情)。
问题: 你能在另一个请求的循环中调用一个请求吗,类似于 MySQL/PHP 当你第一次请求 ID 并且它们循环到return详情?
示例:我想查找目标 ebay-motors 卖家,return 来自这些卖家的一组列表或关键字搜索列表。 (我相信 SDK 将此作为一个请求处理 - ItemFilter SellerID / Keywords)
然后,对于每个列表,我想要每个列表的兼容车辆(这是每个列表的“第二个”loop/request)。
这是我的 "logic"(或缺少)以获得我想要的结果。如果我不能使用循环但我可以 "join" 像电子表格那样向兼容列表列出,那也可以。
//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
);
}
重新请求更多详细信息似乎有些矫枉过正。
查找服务没有return您需要的兼容性信息。对于每个 returned 的项目,您必须在购物服务中单独调用 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);
问这个问题之前,我是一个公认的SDK新手,现在对我来说都是一个挣扎,另外,我想我可能还没有完全理解Ebay的policies/limits .我不确定 "allowed" 或 "proper" 是什么,所以我不会因为不当使用而被阻止(比如太多电话或类似的事情)。
问题: 你能在另一个请求的循环中调用一个请求吗,类似于 MySQL/PHP 当你第一次请求 ID 并且它们循环到return详情?
示例:我想查找目标 ebay-motors 卖家,return 来自这些卖家的一组列表或关键字搜索列表。 (我相信 SDK 将此作为一个请求处理 - ItemFilter SellerID / Keywords)
然后,对于每个列表,我想要每个列表的兼容车辆(这是每个列表的“第二个”loop/request)。
这是我的 "logic"(或缺少)以获得我想要的结果。如果我不能使用循环但我可以 "join" 像电子表格那样向兼容列表列出,那也可以。
//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
);
}
重新请求更多详细信息似乎有些矫枉过正。
查找服务没有return您需要的兼容性信息。对于每个 returned 的项目,您必须在购物服务中单独调用 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);