S
S
Sergey Bard2017-02-10 11:44:26
Google
Sergey Bard, 2017-02-10 11:44:26

How to use the Google Analytics library?

Hello. I use the client library for Google Analytics For authorization, I use the following code (below), but the problem is that it only works if I am logged in under the account for which the data is specified. You can somehow modify the code so that authorization occurs only inside the code and only when it works?, so that you can register access from the desired account inside the script, that is, I can be under another account while the script is running. I'm sorry if I explained it badly)

// Загрузка клиентской библиотеки PHP для Google API.
require_once DIR . '/vendor/autoload.php';

session_start();

$client = new Google_Client(); $client->setAuthConfig(DIR . '/client_secrets.json'); $client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);

// Если пользователь уже авторизовал это приложение, предоставьте токен доступа. // В противном случае перенаправьте пользователя на страницу авторизации доступа в Google Analytics. if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { // Установка токена доступа на клиентском компьютере. $client->setAccessToken($_SESSION['access_token']);

// Создание авторизованного объекта службы аналитики. $analytics = new Google_Service_AnalyticsReporting($client);

// Вызов the Analytics Reporting API V4. $response = getReport($analytics);

// Вывод ответа. printResults($response);

} else { $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/apsga/oauth2callback.php'; header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); }

For a clearer understanding of what I want ...
I need him in this place
// Если пользователь уже авторизовал это приложение, предоставьте токен доступа. // В противном случае перенаправьте пользователя на страницу авторизации доступа в Google Analytics.

did not redirect the user to the access authorization page in Google Analytics, but logged in on the accesses that he was given. If at all possible)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2017-02-10
@SilenceOfWinter

Read the description of the Oauth2 standard, I think the question will disappear by itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question