2015-02-09 164 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

好運學習! :)