English | 简体中文
Now support v1.1
This repo forked from MrSuperLi/tencent-marketing-api-php-sdk
.
Modified the following:
- Integrate authorization.
- Pass
advertiser_id
when instantiate the client. - Use member properties as client to request the API.
- Request param support array.
- Support multiple response types.
- Follow PSR-2.
composer install cloudycity/tencent-marketing-sdk
-
Auth
: the client which to get or refresh token. -
Client
: the main invoker which to get resource client. -
BaseClient
: resource client which to request api. -
Factory
: get resource client in special case.
use CloudyCity\TencentMarketingSDK\Auth;
use CloudyCity\TencentMarketingSDK\Kernel\Exceptions\Exception;
$clientId = '';
$clientSecret = '';
$authCode = '';
$redirectUri = '';
$auth = new Auth($clientId, $clientSecret);
try {
$res = $auth->getTokens($authCode, $redirectUri);
$refreshToken = $res['data']['refresh_token'];
$res = $auth->refreshTokens($refreshToken);
} catch (Exception $e) {
//
}
API standard path: resource/action
demo:
funds/get
get fund infoadvertiser/update
update advertiser
Resources correspond to attributes in the Client
object.
Actions correspond to functions in the attribute of Client
object.
demo:
$res = $client->funds->get();
$res = $client->advertiser->update($params);
use CloudyCity\TencentMarketingSDK\Client;
use CloudyCity\TencentMarketingSDK\Kernel\Http\Parameters\Params;
use CloudyCity\TencentMarketingSDK\Kernel\Exceptions\Exception;
$advertiserId = '';
$accessToken = '';
// You can passing third param to set response type.
// Support types: array (default) / object / collection / raw (json string)
$client = new Client($advertiserId, $accessToken);
// Use `Params` to build params.
$params = Params::make()->setDateRange('2020-01-01', '2020-01-07')
->set('level', 'REPORT_LEVEL_ADGROUP')
->groupBy('adgroup_id', 'date')
->orderBy('cost', 'desc');
$filter = $params->getFilter()
->eq('adgroup_id', 'xxx');
$params->setFilter($filter);
// Or use array
$params = [
'date_range' => [
'start_date' => '2020-01-01',
'end_date' => '2020-01-07',
],
'level' => 'REPORT_LEVEL_ADGROUP',
'group_by' => [
'adgroup_id',
'date'
],
'order_by' => [
'sort_field' => 'cost',
'sort_type' => 'DESCENDING'
],
'filtering' => [
[
'adgroup_id',
'EQUALS',
'xxx'
]
]
];
try {
$res = $client->daily_reports->get($params);
} catch (Exception $e) {
//
}
BaseClient::getAllPages()
implement page turning logic by Generator
.
use CloudyCity\TencentMarketingSDK\Client;
use CloudyCity\TencentMarketingSDK\Kernel\Exceptions\Exception;
$advertiserId = '';
$accessToken = '';
$client = new Client($advertiserId, $accessToken);
try {
foreach ($client->campaigns->getAllPages() as $page) {
foreach ($page as $record) {
var_dump($record);
}
}
} catch (Exception $e) {
//
}
If the SDK update lags behind the API update, new resources which do not exist in the member properties of Client
class may appear.
You can use Factory
class to obtain the BaseClient
instance, but i recommend you open a issue let me create a new member properties for Client
.
use CloudyCity\TencentMarketingSDK\Factory;
$advertiserId = '';
$accessToken = '';
$resourceClient = Factory::getClient('new_resource', $advertiserId, $accessToken);
- @CloudyCity
Feel free to dive in! Open an issue or submit PRs.
Standard Readme follows the Contributor Covenant Code of Conduct.
MIT © CloudyCity