Google Drive OAuth2获取令牌


Google Drive OAuth2 get token

我刚开始学习谷歌树上游戏,我有一些问题。

  1. 如何使用登录链接登录?

    session_start();
    require_once 'api/src/Google/Client.php';
    require_once 'api/src/Google/Service/Drive.php';
    
    $drive = new Google_Client();
    $drive->setClientId('XXXXXXXX-hc0ap9uujjvqpsci9ceitqsrro1d8415.apps.googleusercontent.com'); // Client ID
    $drive->setClientSecret('XXXXXXXXXXX'); //Client Secret
    $drive->setRedirectUri($url);
    $drive->setScopes(array('https://www.googleapis.com/auth/drive'));
    
    $url = $drive->createAuthUrl();
    
  2. 如何获取access_token?

您将从$drive->createAuthUrl()获得登录Google的URL。Google将返回凭据,包括重定向URI的access_token。

我已经在GitHub中建立了一个关于使用API的oAuth和Drive函数的简单评论回购。你可以在这里找到:

https://github.com/numsu/google-drive-sdk-api-php-insert-file-parent-example

祝你学习好运!:)