Hello. I use the client library for Google Analytics. For authorization I use such code (below), but the problem is that it works only if I am logged in under the account for which the data is specified. You can somehow modify the code so that authorization takes place only within the code and only when it is working ?, so that it is possible to register access from the necessary account within the script, that is, i.e. I can be under another at the time of the script. I apologize if explained poorly)
// Загрузка клиентской библиотеки 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
// If the user has already authorized this application, provide an access token. // Otherwise, redirect the user to the Google Analytics access authorization page.
I did not redirect the user to the Google Analytics access authorization page, but he himself logged in for those accesses that he was to register. If at all possible)