flysystem-google-drive icon indicating copy to clipboard operation
flysystem-google-drive copied to clipboard

TeamDrive not working properly (Get file properties, most likely url()

Open michaeljwright opened this issue 6 years ago • 6 comments

Hi,

I set the teamDriveId and folderId (within the TeamDrive), and it lists the files perfectly. However, when I try to click a file to get more file info (filename, mime, thumbnail etc) it fails. If I remove teamDriveId and use a MyDrive folderId it gets/returns more file info fine (works as it should).

I think I've managed to trace the issue to when this is called Storage::cloud()->url(<GDRIVEPATH>) where the path (<GDRIVEPATH>) is correct but returns null. When using normal MyDrive, the public URL is returned fine. So weird, and annoying.

I've also tried various different client_id, secret and tokens but all result in the same issue.

I was wondering if I have to make different API calls in order to get more info from files within a TeamDrive? Are there any more settings that I have to add in my config?

Could really use some help if possible.

Thanks

This is the code (my config file contains the folderId and teamDriveId):

\Storage::extend('google', function($app, $config) { $client = new \Google_Client(); $client->setClientId(config('filesystems.disks.google.clientId')); $client->setClientSecret(config('filesystems.disks.google.clientSecret')); $client->refreshToken(config('filesystems.disks.google.refreshToken')); $service = new \Google_Service_Drive($client); if(config('filesystems.disks.google.teamDriveId')) { $adapter = new GoogleDriveAdapter($service, config('filesystems.disks.google.folderId'), ['teamDriveId' => config('filesystems.disks.google.teamDriveId'), 'files.list' => ['includeTeamDriveItems' => true] ]); } else { $adapter = new GoogleDriveAdapter($service, config('filesystems.disks.google.folderId')); }

        return new \League\Flysystem\Filesystem($adapter);
    });

Attached is the error I get

teamdrive_google_service_exception

michaeljwright avatar Sep 10 '18 15:09 michaeljwright

@michaeljwright I may not be able to give an accurate answer because I am not using a team drive. This adapter has an option to specify file sharing permissions. Is there any change by changing this option?

$adapter = new GoogleDriveAdapter($service, config('filesystems.disks.google.folderId'), [
    'teamDriveId' => config('filesystems.disks.google.teamDriveId'),
    'publishPermission' => [
        'type' => 'domain',
        'role' => 'reader',
        'domain' => 'example.com',
        'withLink' => true
    ]
]);

nao-pon avatar Sep 11 '18 14:09 nao-pon

@nao-pon Thanks so much for replying mate. Unfortunately, that didn't work (as far as I can tell).

I managed to get it working with a rather "hacky" method of replacing the call below (which responds with null on TeamDrives only):

Storage::cloud()->url($files['path'])

With a direct path + the googlefileid:

'https://drive.google.com/a/example.com/uc?id='.$files['basename'].'&export=media'

example.com should be changed to a google g suite domain. I'll be putting the above URL as a config variable. See below for final line.

$projectFile->url = (config('filesystems.disks.google.teamDriveId') ? config('filesystems.disks.google.publicURL').$files['basename'].'&export=media' : Storage::cloud()->url($files['path']));

Hope this helps anyone else who's struggling.

michaeljwright avatar Sep 12 '18 12:09 michaeljwright

@michaeljwright Thank you for testing! Please forget about my previous post. Thank you for posting Tips again. By the way, please tell me about your team drive settings. Is "Allow external access" enabled?

screen shot 2017-07-14 at 4 15 14 pm

see https://productforums.google.com/forum/#!msg/apps/MxSHhKkfrBw/NSqTiHwNAgAJ

nao-pon avatar Sep 12 '18 14:09 nao-pon

@nao-pon Thanks for the great package. It's been really helpful! For above, do you mean sharing for that folder or a file within the folder? I can't see that option, it's greyed out for me (will have to check the permissions I have on the TeamDrive).

I assume the external access / sharing is enabled otherwise "hard coding" the publicUrl wouldn't work: 'https://drive.google.com/a/example.com/uc?id='.$files['basename'].'&export=media'

I'll stick with my "solution" for now (having an extra ENV variable doesn't bother me too much) but will continue to test other ways and keep you posted when I can.

michaeljwright avatar Sep 14 '18 10:09 michaeljwright

@nao-pon Hi, sorry to bother you again. Just wondering if you know of a way to copy entire folders to another path?

michaeljwright avatar Oct 01 '18 16:10 michaeljwright

{ "error": { "errors": [ { "domain": "global", "reason": "notFound", "message": "File not found: 1VE1m2NqpK5Y4PwKnlNC3tnmknz9xqm3q.", "locationType": "parameter", "location": "fileId" } ], "code": 404, "message": "File not found: 1VE1m2NqpK5Y4PwKnlNC3tnmknz9xqm3q." } } How to share Team Drive properly?

leonardooleg avatar Feb 26 '20 23:02 leonardooleg