Javascript Google OAuth2自动登录/自动身份验证

Javascript Google OAuth2自动登录/自动身份验证,javascript,php,google-api,google-drive-api,google-oauth,Javascript,Php,Google Api,Google Drive Api,Google Oauth,我想知道是否有一种可能的方式自动登录到帐户?我正在使用GoogleOAuth2访问GoogleDrive,每次我想使用它时,都会出现一个小窗口来登录。我希望始终保持登录状态。我可以用php/js来做这件事吗?只有管理员才能使用此功能 编辑 基本上我有一个GDrive插件,它工作正常。我想在登录google之前自动调用其他方法,它应该存储在会话中。有可能吗?< P>假设您可以访问您希望访问的驱动器帐户,那么您应该考虑使用服务帐户。服务帐户就像一个虚拟用户,它有自己的驱动器帐户。如果您使用服务帐户电

我想知道是否有一种可能的方式自动登录到帐户?我正在使用GoogleOAuth2访问GoogleDrive,每次我想使用它时,都会出现一个小窗口来登录。我希望始终保持登录状态。我可以用php/js来做这件事吗?只有管理员才能使用此功能

编辑


基本上我有一个GDrive插件,它工作正常。我想在登录google之前自动调用其他方法,它应该存储在会话中。有可能吗?

< P>假设您可以访问您希望访问的驱动器帐户,那么您应该考虑使用服务帐户。服务帐户就像一个虚拟用户,它有自己的驱动器帐户。如果您使用服务帐户电子邮件地址并共享您希望其能够访问的文件或目录,则将对其进行预授权

服务帐户只使用服务器端语言

require_once __DIR__ . '/vendor/autoload.php';
// Use the developers console and download your service account
// credentials in JSON format. Place the file in this directory or
// change the key file location if necessary.
putenv('GOOGLE_APPLICATION_CREDENTIALS='.__DIR__.'/service-account.json');
/**
 * Gets the Google client refreshing auth if needed.
 * Documentation: https://developers.google.com/identity/protocols/OAuth2ServiceAccount
 * Initializes a client object.
 * @return A google client object.
 */
function getGoogleClient() {
    return getServiceAccountClient();
}
/**
 * Builds the Google client object.
 * Documentation: https://developers.google.com/api-client-library/php/auth/service-accounts
 * Scopes will need to be changed depending upon the API's being accessed. 
 * array(Google_Service_Analytics::ANALYTICS_READONLY, Google_Service_Analytics::ANALYTICS)
 * List of Google Scopes: https://developers.google.com/identity/protocols/googlescopes
 * @return A google client object.
 */
function getServiceAccountClient() {
    try {   
        // Create and configure a new client object.        
        $client = new Google_Client();
        $client->useApplicationDefaultCredentials();
        $client->addScope([YOUR SCOPES HERE]);
        return $client;
    } catch (Exception $e) {
        print "An error occurred: " . $e->getMessage();
    }
}

您可以使用谷歌的服务器端登录。你可以阅读更多关于它的内容


基本上,您为google帐户获取访问令牌,并将该令牌与刷新令牌一起存储。您可以使用这些令牌多次从驱动器获取数据。

我已经下载了service-account.json文件(包含类型、项目id、私钥id、私钥、客户端电子邮件、客户端id、身份验证uri、令牌uri、身份验证提供器x509证书url、客户端x509证书url变量),并添加了一个作用域-Google_服务_Drive::Drive,但它似乎不起作用。我什么也没听到。转储对象-。我在编辑中添加了更多信息