Adsensor API
By this library you can use adsensor advertising system, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist adsensor/adsensor-api-php-sdk "dev-master"
or add, (*4)
"adsensor/adsensor-api-php-sdk": "dev-master"
to the require section of your composer.json
file., (*5)
Configuring application
For configuration API add this code:, (*6)
use Adsensor\API\AdMedia;
use Adsensor\API\AdsensorAPI;
use Adsensor\API\Campaign;
use Adsensor\API\TelegramAd;
$token = 'KEY-XXXX';
AdsensorAPI::init($token);
Usage
Get user information and test API:, (*7)
$user = AdsensorAPI::me();
if($user !== null) {
echo '<pre>';
print_r($user);
echo '</pre>';
}
Get list of all categories:, (*8)
// create a new campaign
$campaign = new Campaign();
$categories = $campaign->getCategories();
echo '
';
print_r($categories);
echo '
';
For create a campaign:, (*9)
// 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
}
For uploading a file for campaign:, (*10)
$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
}
Create a new Telegram Ad:, (*11)
$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
}
}
Get a campaign data by ID:, (*12)
$campaign_id = ''; // insert campaign ID here
$campaignInfo = new Campaign($campaign_id);
echo '
';
print_r($campaignInfo->read());
echo '
';
List of your campaigns:, (*13)
$campains = new Campaign();
echo '
';
print_r($campains->all());
echo '
';
Get a Instagram AD data by ID:, (*14)
$instagram_ad_id = ''; // insert Instagram AD ID here
$adInfo = new InstagramAd($instagram_ad_id);
echo '
';
print_r($adInfo->read());
echo '
';