我正在使用来自davidtsadler/ebay-sdk-examples reposity的 02-get-single-item.php代码示例。这是完整的代码示例:
<?php
/**
* Copyright 2016 David T. Sadler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Include the SDK by using the autoloader from Composer.
*/
require __DIR__.'/../vendor/autoload.php';
/**
* Include the configuration values.
*
* Ensure that you have edited the configuration.php file
* to include your application keys.
*/
$config = require __DIR__.'/../configuration.php';
/**
* The namespaces provided by the SDK.
*/
use \DTS\eBaySDK\Shopping\Services;
use \DTS\eBaySDK\Shopping\Types;
use \DTS\eBaySDK\Shopping\Enums;
/**
* Create the service object.
*/
$service = new Services\ShoppingService([
'credentials' => $config['production']['credentials']
]);
/**
* Create the request object.
*/
$request = new Types\GetSingleItemRequestType();
/**
* Specify the item ID of the listing.
*/
$request->ItemID = '111111111111';
/**
* Specify that additional fields need to be returned in the response.
*/
$request->IncludeSelector = 'ItemSpecifics,Variations,Compatibility,Details';
/**
* Send the request.
*/
$response = $service->getSingleItem($request);
/**
* Output the result of calling the service operation.
*/
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') {
$item = $response->Item;
print("$item->Title\n");
printf(
"Quantity sold %s, quantiy available %s\n",
$item->QuantitySold,
$item->Quantity - $item->QuantitySold
);
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->Variations)) {
print("\nThis item has the following variations:\n");
foreach ($item->Variations->Variation as $variation) {
printf(
"\nSKU: %s\nStart Price: %s\n",
$variation->SKU,
$variation->StartPrice->value
);
printf(
"Quantity sold %s, quantiy available %s\n",
$variation->SellingStatus->QuantitySold,
$variation->Quantity - $variation->SellingStatus->QuantitySold
);
foreach ($variation->VariationSpecifics as $specific) {
foreach ($specific->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);
// Only show the first 3.
$limit = min($item->ItemCompatibilityCount, 3);
for ($x = 0; $x < $limit; $x++) {
$compatibility = $item->ItemCompatibilityList->Compatibility[$x];
foreach ($compatibility->NameValueList as $nameValues) {
printf(
"%s: %s\n",
$nameValues->Name,
implode(', ', iterator_to_array($nameValues->Value))
);
}
printf("Notes: %s \n", $compatibility->CompatibilityNotes);
}
}
}
它以前工作正常。但是 eBay 对他们的 API 购物请求进行了一些更改。自 2021 年 7 月 1 日起,在请求标头中还应传递 X-EBAY-API-IAF-TOKEN。他们在GetSingleItem页面上通知。
因此,截至目前,我从 eBay API 收到了以下回复:
RepeatableType {#4019 ▼
-data: array:1 [▼
0 => ErrorType {#4017 ▼
-values: array:5 [▼
"ShortMessage" => "Token not available in request."
"LongMessage" => "Token not available in request. Please specify a valid token as HTTP header."
"ErrorCode" => "1.33"
"SeverityCode" => "Error"
"ErrorClassification" => "RequestError"
]
-attachment: array:2 [▼
"data" => null
"mimeType" => null
]
}
]
-position: 0
-class: "DTS\eBaySDK\Shopping\Types\GetSingleItemResponseType"
-property: "Errors"
-expectedType: "DTS\eBaySDK\Shopping\Types\ErrorType"
}
我正在使用上面的代码,也使用SDK 库来使其工作。
我看到有些人正在更改他们的Shopping/Services/ShoppingBaseService.php,他们将 X-EBAY-API-IAF-TOKEN 添加到代码中:
我尝试了许多不同的方法来解决这个问题,但仍然没有运气。
所以,我的问题是我需要对02-get-single-item.php和Shopping/Services/ShoppingBaseService.php进行哪些更改,以及我需要在哪些地方进行更改才能使 GetSingleItem 请求包含 X-EBAY-API -IAF-TOKEN 在标题中并获得正确的响应?
提前非常感谢!