2012-09-29 81 views
0

我想我的谷歌文檔從一個PHP文件中的文件時,得到了一個致命的錯誤,我寫如下代碼:我使用谷歌驅動API

require_once ("google/Google_Client.php"); 
require_once ("google/contrib/Google_DriveService.php"); 

$client=new Google_Client(); 
$client->setClientId('XXXX'); 
$client->setClientSecret('xxxx'); 
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob'); 
$client->setScopes(array('https://www.googleapis.com/auth/drive')); 
$service = new Google_DriveService($client); 
$parameters=array(); 
$parameters['q'] = "title contains 'something'"; 
$children = $service->children->listChildren('root',$parameters); 
var_dump($children); 

但返回以下信息:

Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/drive/v2/files/root/children?q=title%20contains%20%27something%27 : (404) Not Found'

回答

1

您的應用程序未正確執行OAuth流程,請檢查Google Drive SDK文檔中的PHP快速入門示例以瞭解應如何實施:

https://developers.google.com/drive/quickstart

一旦您的代碼正確執行OAuth流程,您可以替換示例中的代碼以與您一起上傳文件以執行搜索。

+0

thxü首先,我有一個問題更多,我只是想從谷歌驅動器獲得我的谷歌文檔鏈接,並使用谷歌文檔視圖來顯示我的個人網站的文檔,整個操作是隻讀,我每次有人瀏覽我的網站時都不希望獲得許可請求。那麼如何實現這一點?謝謝! –