如何使用PHP中的Ebay API更改产品数量

时间:2014-11-30 17:28:20

标签: php xml ebay ebay-api

我正在尝试做一件简单的事情。 我想使用PHP 更改ebay上现有固定价格商品的数量。这可能吗?我之前问过这个问题并得到回复告诉我要阅读这个或那个。我无法找到任何实际的代码示例。我很乐意看到有人发帖。例如,ebay项目编号123456789的数量为50.我想运行一些PHP代码将其更改为20的数量。我想输入项目编号,新数量以及代码中所需的任何ebay验证数据运行。这就是我所需要的一切。 感谢

3 个答案:

答案 0 :(得分:4)

试试这个对我有用

$feed = <<< EOD
<?xml version="1.0" encoding="utf-8"?>
<ReviseItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>$eBay->auth_token</eBayAuthToken>
</RequesterCredentials>
<Item ComplexType="ItemType">
<ItemID>$itemid</ItemID>
<Quantity> int </Quantity>
</Item>
<MessageID>1</MessageID>
<WarningLevel>High</WarningLevel>
<Version>$eBay->api_version</Version>
</ReviseItemRequest>​
EOD;

$feed = trim($feed);
        $site_id = 3;//3 For UK
        $headers = array
            (
            'X-EBAY-API-COMPATIBILITY-LEVEL: ' . $this->api_version,
            'X-EBAY-API-DEV-NAME: ' . $this->dev_id,
            'X-EBAY-API-APP-NAME: ' . $this->app_id,
            'X-EBAY-API-CERT-NAME: ' . $this->cert_id,
            'X-EBAY-API-CALL-NAME: ' . $call_name,
            'X-EBAY-API-SITEID: ' . $site_id,
        );

        // Send request to eBay and load response in $response
        $connection = curl_init();
        curl_setopt($connection, CURLOPT_URL, $this->api_endpoint);
        curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($connection, CURLOPT_POST, 1);
        curl_setopt($connection, CURLOPT_POSTFIELDS, $feed);
        curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
        $response = curl_exec($connection);
        curl_close($connection);

答案 1 :(得分:4)

有三个选项可用于更新易趣上的直播项目。

为了快速更新商品的数量,您可能希望使用ReviseInventoryStatus,因为它比其他商品具有一些优势。

如果你可以在PHP项目中使用Composer,我已经开发了一个SDK,它简化了使用eBay API的过程。下面的示例显示了如何将SDK与ReviseInventoryStatus一起使用。代码中的注释应告诉您需要更改的内容才能使其起作用。

<?php
require 'vendor/autoload.php';

use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
use \DTS\eBaySDK\Trading\Enums;

// Your authorization token associated with the seller's account.
$authToken = 'abcd123';
// The ID of the item you wish to update (Must be a string).
$itemID = '123456789';
// The new quantity (Must be an integer and not a string!).
$quantity = 20;
// The numerical ID of the site that the item was listed on. For example the site ID for ebay.com is 0 and for ebay.co.uk it is 3. A complete list is available from eBay: http://developer.ebay.com/DevZone/XML/docs/Reference/ebay/types/SiteCodeType.html.
$siteID = '0';

$service = new Services\TradingService(array(
    'authToken' => $authToken,
    'apiVersion' => '899',
    'siteId' => $siteID
));

$request = new Types\ReviseInventoryStatusRequestType();
$inventoryStatus = new Types\InventoryStatusType();
$inventoryStatus->ItemID = $itemID;
$inventoryStatus->Quantity = $quantity;
$request->InventoryStatus[] = $inventoryStatus;
$request->ErrorLanguage = 'en_US';
$request->WarningLevel = 'High';

$response = $service->reviseInventoryStatus($request);

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') {
    foreach ($response->InventoryStatus as $inventoryStatus) {
        printf("Quantity for [%s] is %s\n\n",
            $inventoryStatus->ItemID,
            $inventoryStatus->Quantity
        );
    }
}

如果您有兴趣更新某个项目的其他方面,例如它的标题,您将需要使用修订操作之一,因为这些操作旨在更新更多字段。

<?php
require 'vendor/autoload.php';

use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
use \DTS\eBaySDK\Trading\Enums;

// Your authorization token associated with the seller's account.
$authToken = 'abcd123';
// The ID of the item you wish to update (Must be a string).
$itemID = '123456789';
// The new quantity (Must be an integer and not a string!).
$quantity = 20;
// The numerical ID of the site that the item was listed on. For example the site ID for ebay.com is 0 and for ebay.co.uk it is 3. A complete list is available from eBay: http://developer.ebay.com/DevZone/XML/docs/Reference/ebay/types/SiteCodeType.html.
$siteID = '0';

$service = new Services\TradingService(array(
    'authToken' => $authToken,
    'apiVersion' => '899',
    'siteId' => $siteID
));

$request = new Types\ReviseItemRequestType();
$item = new Types\ItemType();
$item->ItemID = $itemID;
$item->Quantity = $quantity;
$request->Item = $item;
$request->ErrorLanguage = 'en_US';
$request->WarningLevel = 'High';

$response = $service->reviseItem($request);

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') {
    printf("Quantity for [%s] has been updated\n\n", $itemID);
}

答案 2 :(得分:1)

这是一个准备测试的示例,只需替换项目ID和数量。

这个php代码是通过点击&#34;检索php代码&#34;从this site生成的。按钮。 php的SDK也可以在那里下载。

require_once 'EbatNs_Session.php';
require_once 'EbatNs_Logger.php';
require_once 'EbatNs_ServiceProxy.php';
require_once 'EbatNs_Session.php';
require_once 'EbatNs_DataConverter.php';

$session = new EbatNs_Session();
$session->setSiteId(0);
$session->setUseHttpCompression(1);
$session->setAppMode(0);
$session->setDevId(YOUR_DEV_ID_HERE);
$session->setAppId(YOUR_APP_ID_HERE);
$session->setCertId(YOUR_CERT_ID_HERE);
$session->setRequestToken(YOUR_TOKEN_HERE);
$session->setTokenUsePickupFile(false);
$session->setTokenMode(true);

require_once 'EbatNs_ServiceProxy.php';
$proxy = new EbatNs_ServiceProxy($session, 'EbatNs_DataConverterUtf8');

require_once 'ReviseInventoryStatusRequestType.php';
$reviseinventorystatusrequest = new ReviseInventoryStatusRequestType();
$inventorystatus = new InventoryStatusType();
$reviseinventorystatusrequest->addInventoryStatus($inventorystatus);
$inventorystatus->setItemID("YOUR ITEM ID");
$inventorystatus->setQuantity("YOUR QUANTITY");
$reviseinventorystatusrequest->setErrorLanguage("en_US");
$reviseinventorystatusrequest->setVersion("899");
$reviseinventorystatusrequest->setWarningLevel("High");

$response = $proxy->ReviseInventoryStatus($reviseinventorystatusrequest);
相关问题
最新问题