Google 애널리틱스의 사용자 정보를 표시하는 회사에서 개발 중이지만 올 때마다 사용자가 자신의 계정을 승인하거나 로그인하지 못하도록하려는이 패널이 있습니다. 패널에.Google 애널리틱스 API 자동 로그인
처음으로 패널을 사용하여 자신의 Google 계정에 연결하면 일부 정보가 저장되며 다음에 내 패널에 연결하면이 저장된 정보를 사용하여 로그온하게됩니다. 자신의 계정이므로 Google 계정이 연결되어 있지 않아도 해당 정보를 요청하지 않고 웹 로그 분석 정보를 나열 할 수 있습니다.
기본적으로 계정에 자동으로 로그인하고 '앱'에 정보를 표시 할 수 있습니다.
Google 계정이 연결되어있는 경우 API에 연결하는 코드가 이미 있습니다. 로그인 코드가없는 로그인 화면이 표시됩니다. 그렇게 할 수있는 방법이
<?php
require_once 'Google/Client.php';
require_once 'Google/Service/Analytics.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Google Analytics PHP Starter Application");
$client->setClientId('KEY');
$client->setClientSecret('SECRET');
$client->setRedirectUri('RETURN URI');
$client->setScopes('https://www.googleapis.com/auth/analytics.readonly');
$client->setAccessType('offline');
$service = new Google_Service_Analytics($client);
if(isset($_GET['logout']))
{
unset($_SESSION['token']);
}
if(isset($_GET['code']))
{
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if(isset($_SESSION['token']))
{
$client->setAccessToken($_SESSION['token']);
}
if($client->getAccessToken())
{
$props = $service->management_webproperties->listManagementWebproperties("12008145");//~all
print "<h1>Web Properties</h1><pre>" . print_r($props, true) . "</pre>";
$accounts = $service->management_accounts->listManagementAccounts();
//print "<h1>Accounts</h1><pre>" . print_r($accounts, true) . "</pre>";
$segments = $service->management_segments->listManagementSegments();
//print "<h1>Segments</h1><pre>" . print_r($segments, true) . "</pre>";
$goals = $service->management_goals->listManagementGoals("~all", "~all", "~all");
//print "<h1>Goals</h1><pre>" . print_r($goals, true) . "</pre>";
$_SESSION['token'] = $client->getAccessToken();
}
else
{
$authUrl = $client->createAuthUrl();
header("Location: " . $authUrl);
}
?>
있나요 :
무엇 내가 지금까지 가지고하는 것은 이것이다? 나는 주변 곳곳을 찾아 보았고 그 근처에서 뭔가를 찾을 수 없었다.
당신은 [새로 고침 토큰]을 사용할 수 있습니다 (https://developers.google.com/accounts/docs/OAuth2WebServer# 오프라인) 또는 [서비스 계정] (https://code.google.com/p/google-api-php-client/wiki/OAuth2#Service_Accounts)을 클릭하십시오. 새로 고침 토큰을 사용하려면 로그인하여 새로 고침 토큰을 저장 한 다음 액세스 권한을 부여해야합니다. 새로 고침 토큰을 취소하거나 작업을 중지 할 수 있으므로 모든 문서를 읽으십시오. –
Google Analytics 또는 다른 사람들의 Google Analytics에서 데이터에 액세스하고 있습니까? – DaImTo
다른 사람들의 데이터에 액세스하고 있습니다. – Terkhos