I’m having issues with the Google Drive API. I’m trying to access Shared Drives using a service account in PHP. Here’s what I’ve done:
Set up a Google Client with the necessary scopes
Created a Drive service
Tried to list drives with and without parameters
My code works fine without params, but it returns an empty list (which is expected for a service account). However, when I include parameters like ‘useDomainAdminAccess’ and ‘q’, I get a 400 error mentioning ‘Invalid Value’.
I’ve experimented with various query strings and even tried passing only ‘useDomainAdminAccess’ by itself, yet the error still points to the ‘q’ parameter as the issue.
I’ve encountered this issue before, and it can be quite frustrating. The problem lies in how the ‘drives.list’ method works. As alexj mentioned, it doesn’t support querying by name. Here’s what I’d suggest:
First, remove the ‘q’ parameter entirely. Then, fetch all drives using just ‘useDomainAdminAccess’ set to true. Once you have the list, you can filter it in your PHP code.
Also, ensure your service account has been added to the Shared Drives you’re trying to access. Without proper permissions, you’ll get an empty list even if everything else is correct.
hey tom, i had a similar issue. try removing the ‘q’ parameter completely. the drives.list method doesn’t support searching by name. instead, you could fetch all drives and filter them in your code. also, make sure your service account has the necessary permissions. hope this helps!
I’ve been working with the Google Drive API for a while now, and I can shed some light on your issue. The ‘drives.list’ method is indeed tricky when it comes to service accounts.
One thing that’s often overlooked is the importance of domain-wide delegation. Make sure your service account has been properly set up with domain-wide authority in the Google Workspace admin console. This step is crucial for accessing shared drives.
Another tip: instead of using ‘q’ parameter, try fetching all drives first and then filtering on your end. It’s a bit more work, but it’s more reliable. Something like this might work:
This approach has worked well for me in similar situations. If you’re still hitting roadblocks, double-check your OAuth consent screen settings. Sometimes, the issue lies there rather than in the code itself.