PHP code example of victordevphp / tiktok-ads

1. Go to this page and download the library: Download victordevphp/tiktok-ads 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/ */

    

victordevphp / tiktok-ads example snippets


use TikTokAds\Report\ReportManager;

$reportManager = new ReportManager("SEU_TOKEN_DE_ACESSO");

$params = [
    'advertiser_id' => '0000000000000000000',
    'report_type' => 'BASIC',
    'dimensions' => ['adgroup_id'],
    'data_level' => 'AUCTION_ADGROUP',
    'start_date' => '2024-12-01',
    'end_date' => '2024-12-30',
    'metrics' => [
        "campaign_id", "campaign_name", "impressions", "clicks", "conversion", 
        "budget", "spend", "onsite_form", "onsite_shopping", 
        "onsite_initiate_checkout_count", "onsite_on_web_cart", "onsite_add_billing"
    ]
];

$response = $reportManager->getReport($params);
print_r($response);

use TikTokAds\Advertiser\Advertiser;

$advertiser = new Advertiser("SEU_TOKEN_DE_ACESSO");

$params = [
    'advertiser_ids' => ['0000000000000000000'],
    'fields' => ["balance"]
];

$response = $advertiser->getInfo($params);
print_r($response);