[英]How can I retrieve all files in a specific folder?
我發現這是一個解決方案,但它對我不起作用:
$optParams = array('pageSize' => 10, 'fields' => "nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents)", 'q ' => "'".$folderId."' 在父母中" ); $results = $service->files->listFiles($optParams);
這是我的代碼:
$client->setClientSecret('xxxxxx'); $client->setRedirectUri(' https://wosbc.com/oauth2callback.php '); $client->setScopes(' https://www.googleapis.com/auth/readonly '); $client->setAccessType('offline'); $client->setPrompt('同意');
$credentialsPath = "credentials.json";
if (file_exists("credentials.json")) { $access_token = (file_get_contents("credentials.json")); $client->setAccessToken($access_token); //如果令牌過期,則刷新令牌。 if ($client->isAccessTokenExpired()) { echo "accesstoken 已過期
"; $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken()); file_put_contents($credentialsPath, json_encode($client->getAccessToken())); echo "保存的getAccessToken
"; } $drive_service = new Google_Service_Drive($client); //$mp3array = $drive_service->files->listFiles(array())->getFiles(); 有效,但不按文件夾列出 $folderid = "xxxxxxxxx" ;
$optParams = array('pageSize' => 10, 'fields' => "id, name", 'q' => "'".$folderId."' in parents"); $mp3array = $drive_service->files->listFiles($optParams);
對不起,代碼格式化的方式。 這產生了以下錯誤:
致命錯誤:未捕獲的 Google_Service_Exception:{“error”:{“errors”:[ {“domain”:“global”、“reason”:“notFound”、“message”:“找不到文件:.”、“locationType”: “參數”,“位置”:“fileId”}],“代碼”:404,“消息”:“找不到文件:。” } } 在 /home/wosbccom/public_html/google-api-php-client-2.4.1/src/Google/Http/REST.php:119 堆棧跟蹤:#0 /home/wosbccom/public_html/google-api-php -client-2.4.1/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 /home/wosbccom/public_html/google-api-php-client-2.4.1/src/Google/Task/Runner.php(176): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\ Psr7\Request), 'Google_Service_...') #2 /home/wosbccom/public_html/google-api-php-client-2.4.1/src/Google/Http/REST.php(58): Google_Task_Runner->run () #3 /home/wosbccom/public_html/google-api-php-client-2.4.1/src/Google/Client.php(842): Google_Http_REST::execute(對象(在 /home/wosbccom/public_html/google -api-php-client-2.4.1/src/Google/Http/REST.php 在第 119 行
你能告訴我我做錯了什么嗎?
在您的腳本中, $folderid = "xxxxxxxxx"; 被聲明為 $folderid。 但是 $folderId 用於 'q' => "'".$folderId."' in parents"。 我認為 i 和 I 之間的拼寫錯誤是您當前錯誤消息的原因。 你可以通過修改這個來測試你的腳本嗎?
在您的腳本中, $folderid = "xxxxxxxxx";
被聲明為$folderid
。 但是$folderId
用於'q' => "'".$folderId."' in parents"
。 我認為i
和I
之間的拼寫錯誤是您當前錯誤消息的原因。
請進行如下修改。
$folderid = "xxxxxxxxx";
$folderId = "xxxxxxxxx";
或者
'q' => "'".$folderId."' in parents
'q' => "'".$folderid."' in parents
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.