PHP code example of christianjbrown / ebay-browse-api-sdk
1. Go to this page and download the library: Download christianjbrown/ebay-browse-api-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
christianjbrown / ebay-browse-api-sdk example snippets
use ChristianBrown\EBay\Browse\BrowseFactory;
use ChristianBrown\EBay\Browse\Enums\MarketplaceId;
use ChristianBrown\EBay\Browse\Http\ApiHost;
use ChristianBrown\EBay\Browse\Marketplace;
use ChristianBrown\KeyValueStore\MemoryKeyValueStore;
use Symfony\Component\Clock\NativeClock;
$browse = (new BrowseFactory(ApiHost::production()))->create(
'your-client-id',
'your-client-secret',
new Marketplace(MarketplaceId::EBAY_GB), // optionally: end-user context, Accept-Language
new MemoryKeyValueStore(new NativeClock())
);
$itemApi = $browse->getItemApi(); // ItemApiInterface
$itemSummaryApi = $browse->getItemSummaryApi(); // ItemSummaryApiInterface
$compatibilityApi = $browse->getItemCompatibilityApi(); // ItemCompatibilityApiInterface
use ChristianBrown\EBay\Browse\BrowseFactory;
use ChristianBrown\EBay\Browse\Http\ApiHost;
$browse = (new BrowseFactory(ApiHost::sandbox()))->create(
'your-sandbox-client-id',
'your-sandbox-client-secret',
new Marketplace(MarketplaceId::EBAY_GB),
new MemoryKeyValueStore(new NativeClock())
);
use ChristianBrown\EBay\Browse\Exception\ExceptionInterface;
try {
$item = $itemApi->getOneByLegacyId('210987654321');
} catch (ExceptionInterface $exception) {
// Anything this library throws lands here.
}
use ChristianBrown\EBay\Browse\Exception\ItemNotFoundException;
try {
$item = $itemApi->getOneByLegacyId($legacyItemId);
} catch (ItemNotFoundException) {
// The listing has ended — not an error worth retrying.
}
use ChristianBrown\ApiClient\ApiClientFactory;
use ChristianBrown\ApiClient\ClientOptions;
use ChristianBrown\EBay\Browse\Auth\Credentials;
use ChristianBrown\EBay\Browse\Enums\MarketplaceId;
use ChristianBrown\EBay\Browse\Http\ApiHost;
use ChristianBrown\EBay\Browse\Marketplace;
use ChristianBrown\KeyValueStore\MemoryKeyValueStore;
use ChristianBrown\OAuth2Client\ClientCredentialsTokenManagerFactory;
use ChristianBrown\OAuth2Client\Lock\NullLock;
use Symfony\Component\Clock\NativeClock;
// Shared JSON request sender (wires Guzzle for you).
$requestSender = (new ApiClientFactory(new ClientOptions()))->create()->getJsonApiRequestSender();
// ApiHost::production() talks to api.ebay.com; ApiHost::sandbox() switches
// every client and the token exchange below to eBay's sandbox gateway.
$apiHost = ApiHost::production();
// OAuth2 client-credentials machinery. The lock is
use ChristianBrown\EBay\Browse\Api\ItemCompatibilityApi;
use ChristianBrown\EBay\Browse\Transformer\CompatibilityResponseTransformer;
use ChristianBrown\EBay\Browse\Transformer\ErrorParametersTransformer;
use ChristianBrown\EBay\Browse\Transformer\ErrorParameterTransformer;
use ChristianBrown\EBay\Browse\Transformer\ErrorsTransformer;
use ChristianBrown\EBay\Browse\Transformer\ErrorTransformer;
use ChristianBrown\EBay\Browse\Transformer\StringsTransformer;
$errorsTransformer = new ErrorsTransformer(
new ErrorTransformer(
new ErrorParametersTransformer(new ErrorParameterTransformer()),
new StringsTransformer()
)
);
$compatibilityApi = new ItemCompatibilityApi(
$requestSender,
new CompatibilityResponseTransformer($errorsTransformer),
$credentials,
$apiHost
);
use ChristianBrown\EBay\Browse\Api\ItemApi;
use ChristianBrown\EBay\Browse\Cache\ArrayKeyedCache;
$itemApi = new ItemApi(
$requestSender,
$itemTransformer,
$itemGroupTransformer,
$credentials,
$apiHost,
new ArrayKeyedCache(), // getOneById()
new ArrayKeyedCache(), // getOneByLegacyId()
new ArrayKeyedCache(), // getMultipleByItemGroupId()
$itemsResponseTransformer,
new ArrayKeyedCache() // getItems()
);
// 1.x
$browse = new Browse($clientId, $clientSecret, $marketplace, $store);
$browse = new Browse($clientId, $clientSecret, $marketplace, $store, ApiHost::sandbox());
// 2.0
$browse = (new BrowseFactory(ApiHost::production()))->create($clientId, $clientSecret, $marketplace, $store);
$browse = (new BrowseFactory(ApiHost::sandbox()))->create($clientId, $clientSecret, $marketplace, $store);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.