繁体   English   中英

如何检索特定文件夹中的所有文件?

[英]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" 我认为iI之间的拼写错误是您当前错误消息的原因。

请进行如下修改。

从:

$folderid = "xxxxxxxxx";

至:

$folderId = "xxxxxxxxx";

或者

从:

'q' => "'".$folderId."' in parents

至:

'q' => "'".$folderid."' in parents

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM