$result = $managementClient->grants()->getGrant($_GET['counterId'], $_GET['userLogin'])->toArray(); } break; case 'getOperation': //GET /management/v1/counter/{counterId}/operation/{operationId} /** * @see http://api.yandex.ru/metrika/doc/beta/management/operations/operation.xml */ if (isset($_GET['operationId'], $_GET['counterId']) && $_GET['operationId'] && $_GET['counterId']) { $result = $managementClient->operations()->getOperation($_GET['operationId'], $_GET['counterId'])->toArray(); } break; case 'getPageViewsCount': if (isset($_GET['counterId']) && $_GET['counterId']) { $paramsObj = new \Yandex\Metrica\Analytics\Models\Params(); $paramsObj->setMetrics('ga:pageviews')->setStartDate('6daysAgo')->setEndDate('today')->setIds('ga:' . $_GET['counterId']); $analyticsClient = new AnalyticsClient($_COOKIE['yaAccessToken']); $response = $analyticsClient->ga()->getGaData($paramsObj); $result = $response->getRows(); if (empty($result)) { $result = 0; } else { $result = current(current($result)); } } break; } } if (isset($_POST['method'])) { switch ($_POST['method']) { case 'addCounter':
/** * User: tanchik * Date: 28.07.14 13:32 */ use Yandex\Metrica\Analytics\AnalyticsClient; $data = array(); $errorMessage = false; //Is auth if (isset($_COOKIE['yaAccessToken']) && isset($_COOKIE['yaClientId'])) { $settings = (require_once '../../settings.php'); try { $analyticsClient = new AnalyticsClient($_COOKIE['yaClientId']); if (isset($_GET['counter-id']) && $_GET['counter-id']) { $counterId = $_GET['counter-id']; $paramsObj = new \Yandex\Metrica\Analytics\Models\Params(); $paramsObj->setMetrics(\Yandex\Metrica\Analytics\MetricConst::GA_PAGE_VIEWS)->setStartDate('6daysAgo')->setEndDate('today')->setIds('ga:' . $_GET['counter-id'])->setDimensions(\Yandex\Metrica\Analytics\DimensionsConst::GA_COUNTRY); $analyticsClient = new AnalyticsClient($_COOKIE['yaAccessToken']); /** * @see http://api.yandex.ru/metrika/doc/beta/ga/queries/requestjson.xml */ $data = $analyticsClient->ga()->getGaData($paramsObj); } } catch (\Exception $ex) { $errorMessage = $ex->getMessage(); if ($errorMessage === 'PlatformNotAllowed') { $errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте ' . '<a href="/examples/OAuth/">авторизироваться</a> и повторить.</p>'; } } } ?> <!doctype html>