PHP code example of kadam / php-sdk

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

    

kadam / php-sdk example snippets




$appId = 10;
$secretKey = 'you_secret_key'; // or token if auth by bearer token

// initial with signature
$kadamApi = new \kadam\KadamApi($appId, $secretKey);



$appId = 10;
$token = 'you_bearer_token';

// initial with bearer token
$kadamApi = new \kadam\KadamApi($appId, $token, \kadam\KadamApi::MODE_BEARER);

/** @var \kadam\KadamApi $kadamApi */
$id = $kadamApi->createCampaign([
    'ad_format' => 10, // teaser
    'cost_type' => 0, // cpc
    'name' => 'Ads campaign',
    'linkUrl' => 'https://darkfriend.ru',
    'realUrl' => 'https://darkfriend.ru',
    'age' => '1,2,4',
    'gender' => 3,
    'tags' => ['key1', 'key2', 'key3'],
    'geoExclude' => 0,
    'langs' => [0,1,2,3,4,5,6,7,8,9,10],
    'cities' => [5819],
    'countries' => [
        187 => [
            'bid' => 0.2,
            'leadCost' => 0.8,
        ],
        83 => [
            'bid' => 0.5,
            'leadCost' => 1,
        ],
        20 => [
            'bid' => 0.5,
            'leadCost' => 1,
        ],
    ],
    'regions' => [50360],
//    'black_list' => ['123', '456'], // if need black list
//    'white_list' => ['321', '654'], // if need  white list
]);
var_dump($id);

$campaignId = 1;
/** @var \kadam\KadamApi $kadamApi */
$id = $kadamApi->updateCampaign($campaignId, [
    'name' => 'Ads campaign update',
    'geoExclude' => 0,
    'langs' => [0,1,2,3,4,5,6,7,8,9,10],
    'cities' => [5819],
    'countries' => [
        187 => [
            'bid' => 0.2,
            'leadCost' => 0.8,
        ],
        83 => [
            'bid' => 0.5,
            'leadCost' => 1,
        ],
        20 => [
            'bid' => 0.5,
            'leadCost' => 1,
        ],
    ],
    'regions' => [50360],
//    'black_list' => ['123', '456'], // if need black list
//    'white_list' => ['321', '654'], // if need  white list
]);
var_dump($id);

$campaignId = [1];
/** @var \kadam\KadamApi $kadamApi */
$stats = $kadamApi->getCampaignStats(
    $campaignId,
    ['date','campaign'],
    '2020-01-01',
    '2020-02-01'
);
var_dump($stats);

$campaignId = [1];
/** @var \kadam\KadamApi $kadamApi */
$stats = $kadamApi->getCampaignPlacementStats(
    $campaignId,
    '2020-01-01',
    '2020-02-01'
);
var_dump($stats);

/** @var \kadam\KadamApi $kadamApi */
$ages = $kadamApi->getAgesTarget();
var_dump($ages);

/** @var \kadam\KadamApi $kadamApi */
$browsers = $kadamApi->getBrowsersTarget();
var_dump($browsers);

/** @var \kadam\KadamApi $kadamApi */
$platforms = $kadamApi->getPlatformsTarget();
var_dump($platforms);

/** @var \kadam\KadamApi $kadamApi */
$langs = $kadamApi->getLangsTarget();
var_dump($langs);

/** @var \kadam\KadamApi $kadamApi */
$devices = $kadamApi->getDevicesTarget();
var_dump($devices);

/** @var \kadam\KadamApi $kadamApi */
$countries = $kadamApi->getCountriesTarget();
var_dump($countries);

/** @var \kadam\KadamApi $kadamApi */
$regions = $kadamApi->getRegionsTarget();
var_dump($regions);

/** @var \kadam\KadamApi $kadamApi */
$cities = $kadamApi->getCitiesTarget();
var_dump($cities);

$campaignId = 1;
$link = 'https://darkfriend.ru/img/darkfriend.jpg';

/** @var \kadam\KadamApi $kadamApi */
$id = $kadamApi->createMaterial($campaignId, 10, [
    'title' => 'Test teaser',
    'linkUrl' => 'https://darkfriend.ru', // schema and host as in campaign
    'linkMedia' => \file_get_contents($link),
//    'linkMediaRect' => $linkRect, // rectangle picture
    'bids' => [
        187 => [
            'bid' => 0.2,
        ],
        83 => [
            'bid' => 0.5,
        ],
    ],
//    'categories' => [1,2,3],
]);
var_dump($id);

$materialId = 1;

/** @var \kadam\KadamApi $kadamApi */
$result = $kadamApi->updateMaterial($materialId, [
    'title' => 'New Title for teaser',
    'bids' => [
        187 => [
            'bid' => 0.3,
        ],
        83 => [
            'bid' => 0.4,
        ],
    ],
//    'categories' => [1,2,3],
]);
var_dump($result);

$materialId = [1];
/** @var \kadam\KadamApi $kadamApi */
$result = $kadamApi->archiveAdvertisements($materialId);
var_dump($result);

$materialId = 1;
/** @var \kadam\KadamApi $kadamApi */
$id = $kadamApi->toggleAdvertisementState(
    $materialId,
    10
);
var_dump($id);

/** @var \kadam\KadamApi $kadamApi */
$sizes = $kadamApi->getBannerSizes();
var_dump($sizes);

$campaignIds = [1];
$creativeIds = [1];
/** @var \kadam\KadamApi $kadamApi */
$stats = $kadamApi->getCreativeStats(
    $campaignIds,
    $creativeIds,
    ['date', 'creative'],
    '2020-01-01',
    '2020-02-01'
);
var_dump($stats);

$url = 'http://site.ru/image.jpg';
// or
// $url = file_get_contents('http://site.ru/image.jpg');
// or 
// $url = file_get_contents(__DIR__.'/image.jpg');
$adType = 10;
/** @var \kadam\KadamApi $kadamApi */
$image = $kadamApi->uploadImage($url,$adType);
var_dump($image);

/** @var \kadam\KadamApi $kadamApi */
$countries = $kadamApi->getGeoCountries();
var_dump($countries);

/** @var \kadam\KadamApi $kadamApi */
$countryId = 2017370;
$regions = $kadamApi->getGeoRegions($countryId);
var_dump($regions);

composer 

array(2) {
  ["count"]=>int
  ["items"]=>
  array {
    [0]=>
    array(2) {
      ["id"]=> int
      ["title"] => string
    }
    [1]=>
    array(2) {
      ["id"]=>int
      ["title"]=>string
    }
    ....
  }
}

array(2) {
  ["count"]=>int
  ["items"]=>
  array {
    [0]=>
    array(2) {
      ["id"]=> int
      ["title"] => string
    }
    [1]=>
    array(2) {
      ["id"]=>int
      ["title"]=>string
    }
    ....
  }
}

array(2) {
  ["count"]=>int
  ["items"]=>
  array {
    [0]=>
    array(2) {
      ["id"]=> int
      ["title"] => string
    }
    [1]=>
    array(2) {
      ["id"]=>int
      ["title"]=>string
    }
    ....
  }
}

array(2) {
  ["count"]=>int
  ["items"]=>
  array {
    [0]=>
    array(2) {
      ["id"]=> int
      ["title"] => string
    }
    [1]=>
    array(2) {
      ["id"]=>int
      ["title"]=>string
    }
    ....
  }
}

array(2) {
  ["count"]=>int
  ["items"]=>
  array {
    [0]=>
    array(2) {
      ["id"] => int
      ["title"] => string
    }
    [1]=>
    array(2) {
      ["id"]=>int
      ["title"]=>string
    }
    ....
  }
}

array(2) {
  ["count"]=>int
  ["items"]=>
  array {
    [0]=>
    array(2) {
      ["id"] => int
      ["title"] => string
    }
    [1]=>
    array(2) {
      ["id"]=>int
      ["title"]=>string
    }
    ....
  }
}

array(2) {
  ["count"]=>int
  ["items"]=>
  array {
    [0]=>
    array(2) {
      ["id"] => int
      ["title"] => string
      ["countryId"] => int
      ["subdivisionId"] => int
    }
    [1]=>
    array(2) {
      ["id"]=>int
      ["title"]=>string
      ["countryId"] => int
      ["subdivisionId"] => int
    }
    ....
  }
}

array(2) {
  ["count"]=>int
  ["items"]=>
  array {
    [0]=>
    array(2) {
      ["id"] => int
      ["title"] => string
      ["countryId"] => int
      ["subdivisionId"] => int
    }
    [1]=>
    array(2) {
      ["id"]=>int
      ["title"]=>string
      ["countryId"] => int
      ["subdivisionId"] => int
    }
    ....
  }
}

array(2) {
  ["count"]=>int
  ["items"]=>
  array {
    [0]=>
    array(2) {
      ["id"] => int
      ["title"] => string
    }
    [1]=>
    array(2) {
      ["id"]=>int
      ["title"]=>string
    }
    ....
  }
}