"Driver [google] is not supported."、"exception":"InvalidArgumentException",同时尝试将 google 驱动器添加为文件系统

"Driver [google] is not supported.", "exception": "InvalidArgumentException", while trying to add google drive as filesystem

我想使用 google 驱动器作为文件系统的磁盘,为此我安装了 "nao-pon/flysystem-google-drive": "~1.1", 软件包并配置 config/filesystem.php 如下

'disks' => [
  'google' => [
    'driver' => 'google',
    'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
    'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
    'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
    'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'),
  ]
],

GoogleDriveServiceProvider

public function boot()
{
  Storage::extend('google', function ($app, $config) {
    $client = new \Google_Client();
    $client->setClientId($config['clientId']);
    $client->setClientSecret($config['clientSecret']);
    $client->refreshToken($config['refreshToken']);
    $service = new \Google_Service_Drive($client);
    $adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, $config['folderId']);
    return new \League\Flysystem\Filesystem($adapter);
  });
}

我已将 .env 上的所有凭据设置如下

FILESYSTEM_CLOUD=google
GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
GOOGLE_DRIVE_CLIENT_SECRET=xxx
GOOGLE_DRIVE_REFRESH_TOKEN=xxx
GOOGLE_DRIVE_FOLDER_ID=xxx

现在,如果我尝试从 google 磁盘 Storage::disk('google')->exists('abc.jpg') 获取任何文件,它会显示

"Driver [google] is not supported.", "exception": "InvalidArgumentException",

看起来一切都配置正确,但您也可以检查您是否将 google 服务提供商注册到 config/app.php,如果没有,则将其添加到提供商数组,如下所示

providers=[
...
App\Providers\GoogleDriveServiceProvider::class,
],