MMCT TEAM
Server IP : 217.21.85.138  /  Your IP : 216.73.216.103
Web Server : LiteSpeed
System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64
User : u915722082 ( 915722082)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u915722082/public_html/todshut-admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/public_html/todshut-admin/api.php
<?php
// Make sure the Composer autoload file is included
require_once __DIR__ . '/vendor/autoload.php';


// Check if the Google Client class is available
if (!class_exists('Google\Client')) {
    die('Error: Google API Client library is not installed or autoloaded correctly.');
}

// Use the Google API Client and Analytics service
use Google\Client;
use Google\Service\Analytics;

// API Key and OAuth 2.0 Client ID
$apiKey = "AIzaSyAv5WApZKfUJeRiXlG5o8w03Dx7pnuPAvA"; 
$clientId = "183379313022-k5aprcju320bh916hi2o7e1vbj7ssv9q.apps.googleusercontent.com";

// Path to credentials.json
$credentialsPath = __DIR__ . '/credentials.json'; 
    
// Create a new Google Client instance
$client = new Client();
$client->setApplicationName("Google Analytics PHP Integration");
$client->setDeveloperKey($apiKey); // API Key
$client->setClientId($clientId); // OAuth 2.0 Client ID

// Set Scopes for Google Analytics
$client->setScopes([
    'https://www.googleapis.com/auth/analytics.readonly', // Read access to Google Analytics
]);

// Authenticate with OAuth 2.0
if (file_exists($credentialsPath)) {
    $client->setAuthConfig($credentialsPath); // Use the credentials file
} else {
    die("Error: Credentials file not found at {$credentialsPath}");
}

// Initialize the Analytics Service
$analytics = new Analytics($client);

// Example: Get Account Summaries
try {
    $accounts = $analytics->management_accountSummaries->listManagementAccountSummaries();

    echo "<h1>Your Google Analytics Accounts:</h1>";
    if (count($accounts->getItems()) > 0) {
        foreach ($accounts->getItems() as $account) {
            echo "Account Name: " . htmlspecialchars($account['name']) . "<br>";
            echo "Account ID: " . htmlspecialchars($account['id']) . "<br><br>";
        }
    } else {
        echo "No accounts found.";
    }
} catch (Exception $e) {
    echo "An error occurred: " . htmlspecialchars($e->getMessage());
}

?>

MMCT - 2023