From a2842f96402dbe1ae343140f65732d58ae55008b Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 4 Jan 2017 15:12:27 +0200 Subject: [PATCH] ga --- backend/controllers/ReportController.php | 20 ++++++++++++++++++++ backend/views/report/index.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/controllers/ReportController.php b/backend/controllers/ReportController.php index fcf8259..9f5954a 100644 --- a/backend/controllers/ReportController.php +++ b/backend/controllers/ReportController.php @@ -18,4 +18,24 @@ class ReportController extends Controller return $this->render('index', [ ]); } + + public function actionCallback() { + // Создание объекта клиента и установка конфигурации авторизации + // из файла client_secrets.json, скачанного из Developers Console. + $client = new Google_Client(); + $client->setAuthConfig(__DIR__ . '/client_secrets.json'); + $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/admin/report/callback'); + $client->addScope(Google_Service_Analytics::ANALYTICS_READONLY); + + // Выполнение процесса авторизации с сервера. + if (! isset($_GET['code'])) { + $auth_url = $client->createAuthUrl(); + header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL)); + } else { + $client->authenticate($_GET['code']); + $_SESSION['access_token'] = $client->getAccessToken(); + $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/'; + header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); + } + } } \ No newline at end of file diff --git a/backend/views/report/index.php b/backend/views/report/index.php index b0457e0..00874ba 100644 --- a/backend/views/report/index.php +++ b/backend/views/report/index.php @@ -46,7 +46,7 @@ if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { printResults($response); } else { - $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php'; + $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/admin/report/callback'; header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); } -- libgit2 0.21.4