public function testGetOperationsClient()
 {
     $token = 'test';
     $metricaClient = new ManagementClient($token);
     $client = $metricaClient->operations();
     $this->assertTrue($client instanceof OperationsClient);
     $this->assertEquals($token, $client->getAccessToken());
 }
use Yandex\Metrica\Management\ManagementClient;
$operations = array();
$errorMessage = false;
$counterId = null;
//Is auth
if (isset($_COOKIE['yaAccessToken']) && isset($_COOKIE['yaClientId'])) {
    $settings = (require_once '../../settings.php');
    try {
        $managementClient = new ManagementClient($_COOKIE['yaAccessToken']);
        if (isset($_GET['counter-id']) && $_GET['counter-id']) {
            $counterId = $_GET['counter-id'];
            //GET /management/v1/counter/{counterId}/operations;
            /**
             * @see http://api.yandex.ru/metrika/doc/beta/management/operations/operations.xml
             */
            $operations = $managementClient->operations()->getOperations($counterId);
        }
    } catch (\Exception $ex) {
        $errorMessage = $ex->getMessage();
        if ($errorMessage === 'PlatformNotAllowed') {
            $errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте ' . '<a href="' . rtrim(str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__), "/") . '/../OAuth/' . '">авторизироваться</a> и повторить.</p>';
        }
    }
}
?>
<!doctype html>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>Yandex.SDK: Metrica Demo</title>
Beispiel #3
0
 case 'getGrant':
     if (isset($_GET['userLogin'], $_GET['counterId']) && $_GET['userLogin'] && $_GET['counterId']) {
         //GET /management/v1/counter/{counterId}/grant/{userLogin}
         /**
          * @see http://api.yandex.ru/metrika/doc/beta/management/grants/grantold.xml
          */
         $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));
         }
     }