Skip to content

Latest commit

 

History

History
222 lines (162 loc) · 5.99 KB

README.en.md

File metadata and controls

222 lines (162 loc) · 5.99 KB

Tencent Marketing SDK

Latest Version on Packagist Software License Build Status StyleCI Quality Score Total Downloads standard-readme compliant

English | 简体中文

内容列表

Introduction

Now support v1.1

This repo forked from MrSuperLi/tencent-marketing-api-php-sdk.

Modified the following:

  1. Integrate authorization.
  2. Pass advertiser_id when instantiate the client.
  3. Use member properties as client to request the API.
  4. Request param support array.
  5. Support multiple response types.
  6. Follow PSR-2.

Installation

composer install cloudycity/tencent-marketing-sdk

Usage

  • 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.

Authorization

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) {
    //
}

Basic

API standard path: resource/action

demo:

  • funds/get get fund info
  • advertiser/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);

Request params & Response types

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) {
    //
}

Paginator

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) {
    //
}

Factory

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);

Maintainers

  • @CloudyCity

Contributing

Feel free to dive in! Open an issue or submit PRs.

Standard Readme follows the Contributor Covenant Code of Conduct.

License

MIT © CloudyCity