https://github.com/bubnov-mikhail/yandex-direct-client
Client for Yandex Direct API
https://github.com/bubnov-mikhail/yandex-direct-client
analytics yandex yandex-direct
Last synced: 24 days ago
JSON representation
Client for Yandex Direct API
- Host: GitHub
- URL: https://github.com/bubnov-mikhail/yandex-direct-client
- Owner: bubnov-mikhail
- Created: 2015-04-22T16:04:47.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-01-23T07:45:12.000Z (over 8 years ago)
- Last Synced: 2025-04-09T11:24:48.743Z (about 2 months ago)
- Topics: analytics, yandex, yandex-direct
- Language: PHP
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# YandexDirectClient
Требует curl-расширение!Пакет для работы с сервисом Яндекс.Direct посредством его API.
* Подготовлен к использованию через Composer
* Определен автолоадер (согласно psr-4)
* Доступны все методы API
* Дополнительно перед отправкой проводится валидация входных данных через json-schema (База наполняется)1) Установка *Composer*
----------------------------------
composer require bubnov/yandex-direct-client
2) Использование
-------------------------------------
```php
GetClientsUnits(['my-user','customer-user']);
/**
* If Response is an array - you can access to each element as in array
*/
foreach($response as $item){
/**
* If the item has a property (see Yandex Direct API docs) - you can access it by getter
*/
echo "\n" . $item->getLogin() . " has units: " . $item->getUnitsRest();
}/**
* Or you can access directly Nth element in array
*/
echo "\nFirst user units: " . $response->get(0)->getUnitsRest();
/**
* Generating WordstatReport
*/
$reportId = $client->CreateNewWordstatReport(['Phrases' => ['Купить холодильник', 'Холодильники недорого']]);
echo "\nReportId: " . $reportId;
/**
* Wait for 10 seconds
*/
sleep(10);
/**
* Getting full reports list
*/
$reports = $client->GetWordstatReportList();
foreach($reports as $report){
/**
* Find report with $reportId and status 'Done'
*/
if($report->getReportID() == $reportId && $report->getStatusReport() === 'Done'){
echo "\nReport is done, reading";
break;
}
}
/**
* Get wordstat report by $reportId
*/
$report = $client->GetWordstatReport($reportId);
foreach($report as $reportPart){
foreach($reportPart->getSearchedWith() as $searchedWith){
echo sprintf(
"\nPhrase `%s` has %d shows \n",
$searchedWith->getPhrase(),
$searchedWith->getShows()
);
}
}
/**
* Deleting wordstat report
*/
$status = $client->DeleteWordstatReport($reportId);
echo $status ? "\nReport successfully deleted" : "\nSomething wrong...";
}
catch (\YandexDirectClient\Exceptions\YandexErrorException $e){
echo "\nYandexErrorException: " . $e->getMessage() . "\nWith details: " . $e->getErrorDetail() . "\n";
}
catch (\Exception $e){
echo "\nException: " . $e->getMessage() . "\n";
}
```3) TODO
-------------------------------------Расширение json schema для методов