![]() ![]() 'clientSecret' => env( 'SECOND_GOOGLE_DRIVE_CLIENT_SECRET'), 'clientId' => env( 'SECOND_GOOGLE_DRIVE_CLIENT_ID'), For example, it can look like this: // file: config/filesystems.php [ Therefore you need to add a second disk in config/filesystems.php. It's possible to use multiple Google Drive connections at the same time in your Laravel applications. Use multiple Google Drive connections at the same time 'teamDriveId' => env( 'MAIN_GOOGLE_DRIVE_TEAM_DRIVE_ID'), The config may look like: // file: config/filesystems.php [ When you want to use Shared Drives (or Team Drives) you have to provide an extra parameter "teamDriveId" in the config. Or you can use it programmatically in your applications: Storage::disk( 'google')->allFiles() In our case this is the folder id: "1jH09RbtkNC8dvpo_Xji8eAVhlTh5-T0f".įrom that moment your application can use that folder as a disk in your application. Next, you can search for the "Google Drive API". To request an API client from Google you have to log in to Google Cloud Console and create a project (if you don't have one, it may take some seconds to create). This chapter is split into three separate chapters. Now your Laravel application is ready to connect to Google Drive, but to authenticate you have to request a client from the Google API console. file: config/app.php [Īpp\Providers\GoogleDriveServiceProvider::class, We need to register our GoogleDriveServiceProvider in config/app.php. $adapter = new GoogleDriveAdapter($service, $config, $options) $service = new \Google_Service_Drive($client) file: app/Providers/GoogleDriveServiceProvider.php setClientId($config) We create a custom service provider in app/Providers/GoogleDriveServiceProvider.php where we extend the storage with a custom filesystem driver. 'folderId' => env( 'MAIN_GOOGLE_DRIVE_FOLDER_ID'), 'refreshToken' => env( 'MAIN_GOOGLE_DRIVE_REFRESH_TOKEN'), ![]() 'clientSecret' => env( 'MAIN_GOOGLE_DRIVE_CLIENT_SECRET'), 'clientId' => env( 'MAIN_GOOGLE_DRIVE_CLIENT_ID'), In the config/filesystems.php you need to define a storage disk that links the provider with the needed credentials stored in your. # want to use shared drives/team drive? # open the shared drive and get the id from the URL #GOOGLE_DRIVE_TEAM_DRIVE_ID=xxx envįILESYSTEM_CLOUD=google # need to exists in config/filesystems.php env file you need to set the correct credentials to connect to Google Drive APIs. With the power of the Laravel filesystem, it is possible to set up multiple storage disks that can be used within the same application, but in this example, I'm showing you the basic setup. composer require nao-pon/flysystem-google-drive:~ 1.1 Version 1.1 uses the Google Drive API V3, which at the time of writing is not deprecated whereas Google Drive API v2 is. I'm using an external package, "nao-pon/flysystem-google-drive" for this. After that the process of requesting a client for Google Drive via Google API console.Īlso, it's possible to use multiple Google Drive connections at the same time as separate disks, that's the latest chapter in the post. In this post, I'll show how you can set up Google Drive as a storage disk via the Laravel filesystem.įirst I'll cover how you set up Google Drive as an external disk in your Laravel application. Your product is now linked to your Google Account and can be accessed from any Chromebook, computer, Apple or Android device with Internet access.For some projects, we use Google Drive (in combination with a personal account or G Suite account) as a storage provider in Laravel projects.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |