goldfinch / trademe-php-api
Trade Me API 的 PHP 客户端
v1
2023-12-07 20:56 UTC
Requires
- php: ^8.1
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: ^7.8
- guzzlehttp/oauth-subscriber: ^0.6.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.7
- phpspec/prophecy: ^1.18
- phpunit/phpunit: ^9.6
- symfony/var-dumper: ^6.3
This package is auto-updated.
Last update: 2024-09-19 08:09:56 UTC
README
Trade Me PHP API
一个非官方的 PHP 客户端,简化了与 Trade Me 的API 平台接口。
安装
composer require goldfinch/trademe-php-api
授权
获取临时访问令牌(步骤 1)
$config = [
'sandbox' => true,
'oauth' => [
'consumer_key' => 'foo',
'consumer_secret' => 'bar',
],
];
$client = new \JPCaparas\TradeMeAPI\Client($config);
['oauth_token' => $tempAccessToken, 'oauth_token_secret' => $tempAccessTokenSecret] = $client->getTemporaryAccessTokens();
获取 OAuth 令牌验证器以验证临时访问令牌(步骤 2)
$tokenVerifierUrl = $client->getAccessTokenVerifierURL($tempOAuthToken); // Visit this URL and store the verifier code
获取最终访问令牌(步骤 3)
// The config values are a culmination of steps 1 and 2
$config = [
'temp_token' => 'baz',
'temp_token_secret' => 'qux',
'token_verifier' => 'quux'
];
['oauth_token' => $accessToken, 'oauth_token_secret' => $accessTokenSecret] = $client->getFinalAccessTokens($config);
进行 API 调用
获取最终访问令牌后,您可以进行 API 调用
出售商品
$config = [
'sandbox' => true,
'oauth' => [
'consumer_key' => 'foo',
'consumer_secret' => 'bar',
'token' => 'baz',
'token_secret' => 'qux',
'token_verifier' => 'quu',
],
];
$client = new Client($config);
$params = [
'Category' => 'TestCategory',
'Title' => 'TestTitle',
'Description' => ['TestDescriptionLine1'],
'Duration' => 1,
'BuyNowPrice' => 99,
'StartPrice' => 90,
'PaymentMethods' => [2, 4],
'Pickup' => 1,
'ShippingOptions' => [
['Type' => 1],
],
];
$client->sellItem($params);
测试
vendor/bin/phpunit