我正在尝试使用此Google教程设置Management API:https://developers.google.com/analytics/devguides/config/mgmt/v3/quickstart/web-php
我已将index.php和oauth2callback.php文件和已编辑的URL下载到固定地址(我使用的是XAMPP,而不是终端,我的文件位于子文件夹中)。
我陷入无线重定向进行Google身份验证。它从不向我显示输出或任何错误。
的index.php:
<?php
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);
if ($_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$analytics = new Google_Service_Analytics($client);
$profile = getFirstProfileId($analytics);
$results = getResults($analytics, $profile);
//printResults($results);
echo $results;
} else {
$redirect_uri = 'http://localhost/zen-analytics/management-api/oauth2callback.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
...
oauth2callback.php:
<?php
require_once __DIR__ . '/vendor/autoload.php';
session_start();
$client = new Google_Client();
$client->setAuthConfig(__DIR__ . '/client_secrets.json');
$client->setRedirectUri = 'http://localhost/zen-analytics/management-api/oauth2callback.php';
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
if (! isset($_GET['code'])) {
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect_uri = 'http://localhost/zen-analytics/management-api/';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
?>
Web应用程序授权的重定向URI设置为: