【问题标题】:Google Drive OAuth2 get tokenGoogle Drive OAuth2 获取令牌
【发布时间】:2015-04-09 18:54:44
【问题描述】:

我刚开始学习 Google tree up play,我有一些问题。

  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?

【问题讨论】:

  • 您在尝试登录时是否遇到任何异常?请描述一下。
  • @Petr。在开始编码之前,您确实需要阅读和理解 OAuth。 OAuth 中没有“登录”。至少有三种不同的方法来获取访问令牌。阅读并理解developers.google.com/accounts/docs/OAuth2

标签: php oauth google-drive-api google-oauth


【解决方案1】:

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

我在 GitHub 中设置了一个关于使用 oAuth 和 Drive 函数和 API 的简单注释存储库。你可以在这里找到它:

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

祝你学习顺利! :)

【讨论】:

    猜你喜欢
    • 2016-10-13
    • 2013-12-27
    • 1970-01-01
    • 2016-10-13
    • 2018-02-27
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 2015-02-11
    相关资源
    最近更新 更多