1. Go to this page and download the library: Download biplane/yandex-direct 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/ */
biplane / yandex-direct example snippets
use Biplane\YandexDirect\ApiServiceFactory;
use Biplane\YandexDirect\Api\V5\Ads;
use Biplane\YandexDirect\Api\V5\Contract;
use Biplane\YandexDirect\ConfigBuilder;
$serviceFactory = new ApiServiceFactory();
$config = ConfigBuilder::create()
->setAccessToken('<INSERT_ACCESS_TOKEN>')
->setClientLogin('agrom')
->setLocale('ru')
->getConfig();
$service = $serviceFactory->createService($config, Ads::class);
$campaignsIds = [123];
$criteria = Contract\AdsSelectionCriteria::create()
->setCampaignIds($campaignsIds)
->setStates([
Contract\StateEnum::ON,
]);
$request = Contract\GetAdsRequest::create()
->setSelectionCriteria($criteria)
->setFieldNames([
Contract\AdFieldEnum::AD_CATEGORIES,
Contract\AdFieldEnum::AGE_LABEL,
Contract\AdFieldEnum::AD_GROUP_ID,
Contract\AdFieldEnum::ID,
Contract\AdFieldEnum::STATUS,
]);
$response = $service->get($request);
foreach ($response->getAds() ?? [] as $item) {
// Здесь $item будет являться экземпляром `Biplane\YandexDirect\Api\V5\Contract\AdGetItem`
// Например, получение информации о возрастной метке:
// $item->getAgeLabel();
}