2012-08-01 84 views
0

https://developers.google.com/drive/v2/reference/children/list谷歌驅動器SDK(PHP)兒童:列表:該列表是空

我使用的文檔

/** 
* Print files belonging to a folder. 
* 
* @param apiDriveService $service Drive API service instance. 
* @param String $folderId ID of the folder to print files from. 
*/ 
function printFilesInFolder($service, $folderId) { 
    $pageToken = NULL; 

    do { 
    try { 
     $parameters = array(); 
     if ($pageToken) { 
     $parameters['pageToken'] = $pageToken; 
     } 
     $children = $service->children->listChildren($folderId, $parameters); 

     foreach ($children->getItems() as $child) { 
     print 'File Id: ' . $child->getId(); 
     } 
     $pageToken = $children->getNextPageToken(); 
    } catch (Exception $e) { 
     print "An error occurred: " . $e->getMessage(); 
     $pageToken = NULL; 
    } 
    } while ($pageToken); 
} 

,我有這個文件夾中的2個文件採取了這種PHP函數,一個是圖片和其他文件夾是,但兒童$ VAR不包含任何項目:

ChildList Object 
(
    [nextPageToken] => 
    [kind] => drive#childList 
    [__itemsType:protected] => ChildReference 
    [__itemsDataType:protected] => array 
    [items] => Array 
     (
     ) 

    [nextLink] => 
    [etag] => "WtRjAPZWbDA7_fkFjc5ojsEvE7I/lmSsH-kN3I4LpwShGKUKAM7cxbI" 
    [selfLink] => https://www.googleapis.com/drive/v2/files/0B--Zn-zouTFrRURaNWp5VDN5LTA/children 
) 

我還檢查folderId,是很好的,所以不會有問題。

我的文件夾: Folder

而且我沒有任何錯誤信息

+1

您使用的範圍是?如果您使用的是https:// www.googleapis.com/auth/drive.file',並且您從未使用Google Drive網絡用戶界面或Picker API在應用中打開這些文件,則這些文件不會顯示在任何API上要求。 – Alain 2012-08-01 21:00:17

+0

是的,我只使用這個範圍,所以可能是它,我必須添加哪一個?好吧,我開始瞭解我之前也有過的其他問題,因爲那樣,那麼......我不知道,非常感謝 – 2012-08-01 21:01:35

+2

如果您希望能夠列出文件,唯一的選擇是使用更廣泛的範圍:'' https://開頭www.googleapis.com/auth /中drive'。請注意,如果不需要列表文件,我們不建議使用此範圍。 – Alain 2012-08-01 21:05:17

回答

1

如果你希望能夠列出文件,唯一的選擇是使用範圍更廣:https://www.googleapis.com/auth/drive。請注意,如果不需要列表文件,我們不建議使用此範圍。通過Alain

相關問題