v1.1
This commit is contained in:
parent
7985ade2ba
commit
e444f992d1
@ -192,3 +192,33 @@ body {
|
|||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
color: #6C757D;
|
color: #6C757D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.integration-connect {
|
||||||
|
margin-bottom: 32px;
|
||||||
|
padding: 24px;
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
border: 1px solid #DEE2E6;
|
||||||
|
border-radius: 8px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
padding: 12px 24px;
|
||||||
|
font-size: 1rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: 500;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background-color: #007BFF;
|
||||||
|
color: #FFFFFF;
|
||||||
|
border: 1px solid #007BFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
|
border-color: #0056b3;
|
||||||
|
}
|
||||||
|
|||||||
1
config/.gitignore
vendored
Normal file
1
config/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
google.php
|
||||||
@ -43,6 +43,9 @@ $chart_data = [
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main class="dashboard-main">
|
<main class="dashboard-main">
|
||||||
|
<div class="integration-connect">
|
||||||
|
<a href="google_auth.php" class="btn btn-primary">Connect to Google Analytics</a>
|
||||||
|
</div>
|
||||||
<div class="dashboard-title">
|
<div class="dashboard-title">
|
||||||
<h1><?php echo htmlspecialchars($client_name); ?>'s Dashboard</h1>
|
<h1><?php echo htmlspecialchars($client_name); ?>'s Dashboard</h1>
|
||||||
<div class="date-range-picker">
|
<div class="date-range-picker">
|
||||||
|
|||||||
16
google_auth.php
Normal file
16
google_auth.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require_once 'config/google.php';
|
||||||
|
|
||||||
|
$auth_url = 'https://accounts.google.com/o/oauth2/v2/auth?' . http_build_query([
|
||||||
|
'client_id' => GOOGLE_CLIENT_ID,
|
||||||
|
'redirect_uri' => GOOGLE_REDIRECT_URI,
|
||||||
|
'response_type' => 'code',
|
||||||
|
'scope' => 'https://www.googleapis.com/auth/analytics.readonly',
|
||||||
|
'access_type' => 'offline',
|
||||||
|
'prompt' => 'consent'
|
||||||
|
]);
|
||||||
|
|
||||||
|
header('Location: ' . $auth_url);
|
||||||
|
exit();
|
||||||
48
google_callback.php
Normal file
48
google_callback.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require_once 'config/google.php';
|
||||||
|
|
||||||
|
if (isset($_GET['code'])) {
|
||||||
|
$code = $_GET['code'];
|
||||||
|
|
||||||
|
$token_url = 'https://oauth2.googleapis.com/token';
|
||||||
|
$token_params = [
|
||||||
|
'code' => $code,
|
||||||
|
'client_id' => GOOGLE_CLIENT_ID,
|
||||||
|
'client_secret' => GOOGLE_CLIENT_SECRET,
|
||||||
|
'redirect_uri' => GOOGLE_REDIRECT_URI,
|
||||||
|
'grant_type' => 'authorization_code'
|
||||||
|
];
|
||||||
|
|
||||||
|
$ch = curl_init($token_url);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($token_params));
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($http_code == 200) {
|
||||||
|
$token_data = json_decode($response, true);
|
||||||
|
|
||||||
|
// For now, just print the token data
|
||||||
|
// In a real application, you would store this securely in a database
|
||||||
|
echo '<pre>';
|
||||||
|
print_r($token_data);
|
||||||
|
echo '</pre>';
|
||||||
|
|
||||||
|
// Store the access token in the session for immediate use
|
||||||
|
$_SESSION['google_access_token'] = $token_data['access_token'];
|
||||||
|
|
||||||
|
// Redirect back to the dashboard
|
||||||
|
// header('Location: dashboard.php');
|
||||||
|
// exit();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
echo "Error fetching access token: " . $response;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "Authorization code not found.";
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user