2015-02-09 162 views
0

我刚开始学习Google树玩,我有一些问题。Google Drive OAuth2获得令牌

  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?

+0

尝试登录时是否遇到任何异常?请认真描述。 – 2015-02-09 21:43:02

+0

@Petr。在开始编码之前,您确实需要阅读并理解OAuth。 OAuth中没有“登录”。至少有三种不同的方法来获取访问令牌。阅读并理解https://developers.google.com/accounts/docs/OAuth2 – pinoyyid 2015-02-10 03:36:43

回答

0

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

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

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

好运学习! :)