0
votes

I found this as a solution, but it didn't work for me:

$optParams = array( 'pageSize' => 10, 'fields' => "nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents)", 'q' => "'".$folderId."' in parents" ); $results = $service->files->listFiles($optParams);

Here is my code:

$client->setClientSecret('xxxxxx'); $client->setRedirectUri('https://wosbc.com/oauth2callback.php'); $client->setScopes('https://www.googleapis.com/auth/readonly'); $client->setAccessType('offline'); $client->setPrompt('consent');

$credentialsPath = "credentials.json";

if (file_exists("credentials.json")) { $access_token = (file_get_contents("credentials.json")); $client->setAccessToken($access_token); //Refresh the token if it's expired. if ($client->isAccessTokenExpired()) { echo "accesstoken is expired
"; $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken()); file_put_contents($credentialsPath, json_encode($client->getAccessToken())); echo "saved getAccessToken
"; } $drive_service = new Google_Service_Drive($client); //$mp3array = $drive_service->files->listFiles(array())->getFiles(); works, but not listing by folder $folderid = "xxxxxxxxx";
$optParams = array( 'pageSize' => 10, 'fields' => "id, name", 'q' => "'".$folderId."' in parents" ); $mp3array = $drive_service->files->listFiles($optParams);

Sorry for the way the code formatted. This produced the following error:

Fatal error: Uncaught Google_Service_Exception: { "error": { "errors": [ { "domain": "global", "reason": "notFound", "message": "File not found: .", "locationType": "parameter", "location": "fileId" } ], "code": 404, "message": "File not found: ." } } in /home/wosbccom/public_html/google-api-php-client-2.4.1/src/Google/Http/REST.php:119 Stack trace: #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(Object( in /home/wosbccom/public_html/google-api-php-client-2.4.1/src/Google/Http/REST.php on line 119

Can you tell me what I did wrong?

1
In your script, $folderid = "xxxxxxxxx"; is declared as $folderid. But $folderId is used at 'q' => "'".$folderId."' in parents". I think that this spelling mistake between i and I is the reason of your current error message. Can you test your script by modifying this? By this, if the error message is not removed or changed, I apologize.Tanaike
Tanaike! That did the trick. Thank you so much for the help. I don't know how to give you official credit for this, but you gave the correct answer.Rich F
Thank you for replying. I'm glad your issue was resolved. About how to give you official credit for this, I posted it as an answer. Could you please confirm it? In this case, you can accept for it like https://meta.stackexchange.com/a/65088.Tanaike

1 Answers

1
votes

In your script, $folderid = "xxxxxxxxx"; is declared as $folderid. But $folderId is used at 'q' => "'".$folderId."' in parents". I think that this spelling mistake between i and I is the reason of your current error message. Can you test your script by modifying this?

In your script, $folderid = "xxxxxxxxx"; is declared as $folderid. But $folderId is used at 'q' => "'".$folderId."' in parents". I think that this spelling mistake between i and I is the reason of your current error message.

Please modify as follows.

From:

$folderid = "xxxxxxxxx";

To:

$folderId = "xxxxxxxxx";

or

From:

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

To:

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