### Install Yandex.Direct PHP Client via Composer Source: https://github.com/biplane/yandex-direct/blob/master/README.md This snippet demonstrates how to install the Yandex.Direct PHP client library using Composer, the popular PHP dependency manager. This command adds the `biplane/yandex-direct` package to your project's dependencies. ```bash $ composer require biplane/yandex-direct ``` -------------------------------- ### Retrieve Ads Data from Yandex.Direct API (PHP) Source: https://github.com/biplane/yandex-direct/blob/master/README.md This PHP example illustrates how to fetch a list of advertisements from the Yandex.Direct Ads service (v5). It shows how to configure the API client with an access token and client login, define selection criteria for ads, and iterate through the retrieved results. ```php setAccessToken('') ->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(); } ``` -------------------------------- ### Generate and Download Yandex.Direct Report (PHP) Source: https://github.com/biplane/yandex-direct/blob/master/README.md This PHP example demonstrates how to request a report from the Yandex.Direct Reports service, wait for its completion, and then save the generated report to a local file. It includes defining report parameters such as name, type, date range, and desired fields. ```php setAccessToken('') ->setClientLogin('agrom') ->setLocale('ru') ->getConfig(); $service = $serviceFactory->createService($config); $reportDefinition = Reports\ReportDefinition::create() ->setReportName('demo') ->setReportType(Reports\ReportTypeEnum::CAMPAIGN_PERFORMANCE_REPORT) ->setDateRangeType(Reports\DateRangeTypeEnum::LAST_7_DAYS) ->setFieldNames([ Reports\FieldEnum::CAMPAIGN_ID, Reports\FieldEnum::CAMPAIGN_NAME, Reports\FieldEnum::IMPRESSIONS, Reports\FieldEnum::CLICKS, Reports\FieldEnum::COST, ]) ->setIncludeVAT(false); $request = Reports\ReportRequestBuilder::create() ->setReportDefinition($reportDefinition) ->returnMoneyInMicros(false) ->skipReportHeader(true) ->getReportRequest(); $result = $service->getReady($request); $result->saveToFile('/path/to/file.tsv'); ``` -------------------------------- ### Configure PSR-3 Logging for Yandex.Direct API (PHP) Source: https://github.com/biplane/yandex-direct/blob/master/README.md This PHP snippet shows how to integrate a PSR-3 compatible logger (e.g., Monolog) with the Yandex.Direct API client. By setting a `PsrLogger` instance, all API requests will be logged. Successful responses are logged at `DEBUG` level, while errors are logged at `ERROR` level. ```php setLogger(new PsrLogger($psrLogger)) ->getFactory(); // ... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.