0

Google アナリティクス php API を使用してデータを取得しています。index.php で認証プロセスが完了しましたが、正常に機能し、このページでログインに成功しました すべてのプロパティを表示する別の php ページへのリンクがあるので、ログイン資格情報を properties.php に投稿して作成する方法すべての Web プロパティを取得するための分析オブジェクト

コードindex.phpは次のようになります

session_start();
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_AnalyticsService.php';



$scriptUri = "http://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF'];

$client = new Google_Client();
$client->setAccessType('online'); // default: offline
$client->setApplicationName('XXXX');
$client->setClientId('XXXXXX');
$client->setClientSecret('XXXXX');
$client->setRedirectUri($scriptUri);
$client->setDeveloperKey('XXXXXX'); // API key
$client->setScopes('https://www.googleapis.com/auth/analytics');


$service = new Google_AnalyticsService($client);
if (isset($_GET['logout'])) { // logout: destroy token
    unset($_SESSION['token']);
    die('Logged out.');
}

if (isset($_GET['code'])) { // we received the positive auth callback, get the token and store it in session
    $client->authenticate();
    $_SESSION['token'] = $client->getAccessToken();
}

if (isset($_SESSION['token'])) { // extract token from session and configure client
    $token = $_SESSION['token'];
    $client->setAccessToken($token);
}

if (!$client->getAccessToken()) { // auth call to google
    $authUrl = $client->createAuthUrl();
    header("Location: ".$authUrl);
    die;
}
TRY{

    }

?>
4

0 に答える 0