相关疑难解决方法(0)

Google API - 强制每次都授予权限

我正在使用Google API PHP客户端.每次我尝试登录时,我都被迫授予应用程序权限.

以下是我的代码.我基本上是访问Google API for Analytics

require_once 'lib/apiClient.php';
require_once 'lib/contrib/apiAnalyticsService.php';
session_start();

$client = new apiClient();
$client->setApplicationName("Google Analytics");

$client->setClientId('7xxxx');
$client->setClientSecret('xxxx');
$client->setRedirectUri('xxxx');
$client->setDeveloperKey('xxxx');

$analytics = new apiAnalyticsService($client);

if (isset($_GET['logout'])) {
    unset($_SESSION['token']);
}

if (isset($_GET['code'])) {
    $client->authenticate();
    $_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()) {
    $profileId = getProfileIds($analytics);

    echo "<select>";
    foreach ($profileId as $profiles) {
        echo "<option value=\"" . $profiles['profileId'] . "\">" . $profiles['name'] .
            "</option>"; …
Run Code Online (Sandbox Code Playgroud)

php google-api google-analytics-api google-api-client

3
推荐指数
1
解决办法
3978
查看次数