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

Har*_*M V 3 php google-api google-analytics-api google-api-client

我正在使用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>";
    }
    echo "</select>";

} else {
    $authUrl = $client->createAuthUrl();
    print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
Run Code Online (Sandbox Code Playgroud)

我们可以将什么选项传递给createAuthUrl()

Har*_*M V 7

通过设置

$client->setApprovalPrompt('auto');
Run Code Online (Sandbox Code Playgroud)

如果帐户有权访问api,它将自动重定向.默认情况下它的"力量"