PHP code example of cloudycity / tencent-marketing-sdk

1. Go to this page and download the library: Download cloudycity/tencent-marketing-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/ */

    

cloudycity / tencent-marketing-sdk example snippets



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

$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 = '';

// 可以传入第三个参数来指定响应类型
// 支持的响应类型: array (default) / object / collection / raw (json string)
$client = new Client($advertiserId, $accessToken);

// 使用`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);

// 或使用数组构建参数
$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) {
    //
}


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


use CloudyCity\TencentMarketingSDK\Factory;

$advertiserId = '';
$accessToken = '';

$resourceClient = Factory::getClient('new_resource', $advertiserId, $accessToken);