PHP code example of adsensor / adsensor-api-php-sdk
1. Go to this page and download the library: Download adsensor/adsensor-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/ */
adsensor / adsensor-api-php-sdk example snippets
use Adsensor\API\AdMedia;
use Adsensor\API\AdsensorAPI;
use Adsensor\API\Campaign;
use Adsensor\API\TelegramAd;
$token = 'KEY-XXXX';
AdsensorAPI::init($token);
// create a new campaign
$campaign = new Campaign();
$categories = $campaign->getCategories();
echo '<pre>';
print_r($categories);
echo '</pre>';
// create a new campaign
$campaign = new Campaign(null, [
Campaign::NAME => 'campaign name',
Campaign::TYPE => Campaign::TYPE_ENGAGE, // campaign KPI Range : TYPE_ENGAGE - TYPE_VIRAL - TYPE_BRANDING
Campaign::CATEGORY => [1, 2, 3] // categories ID
]);
if( $campaign->validate() && $campaign->create() )
{
// campaign created ...
$campaign_id = $campaign->{Campaign::ID}; // access campaign ID
}
$media = new AdMedia();
$file_path = __DIR__ . '/image.jpg'; // file directory
if( $media->create($file_path) )
{
// new media created successfully
$media_id = $media->{AdMedia::ID}; // access media ID
}
$campaign_id = ''; // insert campaign ID here
$media_id = ''; // insert media ID here
$telegramAd = new TelegramAd(null, $campaign_id);
$telegramAd->setData([
TelegramAd::BUDGET => 3000000, // budget (Rial)
TelegramAd::TEXT => 'test content...', // text of ad
TelegramAd::MEDIA => $media_id // fetch media by ID
]);
if($telegramAd->validate() && $telegramAd->create())
{
// telegram ad created successfully
$telegramAd_id = $telegramAd->{TelegramAd::ID}; // access Ad by ID
// pay & active telegram ad
if( $telegramAd->active() ) {
// Telegram ad activated successfully
}
}
$campaign_id = ''; // insert campaign ID here
$campaignInfo = new Campaign($campaign_id);
echo '<pre>';
print_r($campaignInfo->read());
echo '</pre>';
$campains = new Campaign();
echo '<pre>';
print_r($campains->all());
echo '</pre>';
$instagram_ad_id = ''; // insert Instagram AD ID here
$adInfo = new InstagramAd($instagram_ad_id);
echo '<pre>';
print_r($adInfo->read());
echo '</pre>';
php composer.phar
"adsensor/adsensor-api-php-sdk": "dev-master"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.