PHP code example of tencent-ad / marketing-api-php-sdk

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

    

tencent-ad / marketing-api-php-sdk example snippets



encentAds\TencentAds;

$tads = TencentAds::init([]);
$token = $tads->oauth()
              ->token([ // oauth/token接口即对应oauth()->token()方法
                  'client_id'          => '{your client id}',
                  'client_secret'      => '{your client secret}',
                  'grant_type'         => 'authorization_code',
                  'authorization_code' => '{your authorization code}',
                  'redirect_uri'       => '{your redirect uri}',
              ]);

echo "<pre>" . PHP_EOL;
print_r($token);
echo "</pre>" . PHP_EOL;

$tads->setAccessToken($token->getAccessToken());


encentAds\TencentAds;

$tads = TencentAds::init([
    'access_token' => '{access-token}',
])->useSandbox(); // 默认访问沙箱环境,如访问正式环境,请调用$tads->useProduction()


TencentAds\TencentAds;
use TencentAds\Exception\TencentAdsResponseException;
use TencentAds\Exception\TencentAdsSDKException;

$tads = TencentAds::init([
    'access_token' => '{your access token}',
]);
try {
    $filtering = [
        [
            'field'    => 'promoted_object_type',
            'operator' => 'EQUALS',
            'values'   => ['PROMOTED_OBJECT_TYPE_APP_IOS'],
        ],
    ];
    $response = $tads
        ->campaigns()
        ->get([ // campaigns/get接口即对应campaigns()->get()方法
            'account_id' => '{your account id}',
            'filtering'  => $filtering,
        ]);
    echo "<pre>" . PHP_EOL;
    print_r($response);
    echo "</pre>" . PHP_EOL;
} catch (TencentAdsResponseException $e) {
    // When Api returns an error
    echo 'Tencent ads returned an error: ' . $e->getMessage();
    exit;
} catch (TencentAdsSDKException $e) {
    // When validation fails or other local issues
    echo 'Tencent ads SDK returned an error: ' . $e->getMessage();
    exit;
}


TencentAds\TencentAds;

$tads = TencentAds::init([
    'access_token' => '{access-token}',
    'is_debug'     => true,
    'debug_file'   => '{your log path}', // 不指定,输出到 php://output
]);


TencentAds\TencentAds;

$tads = TencentAds::init([
    'access_token' => '{access-token}',
    'is_monitor'   => false,
]);


TencentAds\TencentAds;
use TencentAds\Kernel\SerializerHandler;

$tads = TencentAds::init([
    'access_token' => '{access-token}',
    'is_monitor'   => false,
]);

$tads->setSerializerType(SerializerHandler::SERIALIZER_TYPE_ARRAY);
json
{
  "cent-ad/marketing-api-php-sdk" : "*"
  }
}