问题描述
refresh token must be passed in or set as part of setAccesstoken
来自 GoogleDriveServiceProvider 的代码:
class GoogleDriveServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Storage::extend('google',function($app,$config) {
$client = new Google_Client();
$client->setClientId($config['clientId']);
$client->setClientSecret($config['clientSecret']);
$client->setAccesstype('offline');
$client->refreshToken($config['refreshToken']);
$service = new \Google_Service_Drive($client);
$adapter = new GoogleDriveAdapter($service,$config['folderId']);
return new Filesystem($adapter);
});
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
我试图将文本文件上传到 Google 云端硬盘的控制器代码:
Storage::disk('google')->put('test.txt','Hello World');
关于这个主题有几个答案,但他们有干净的 PHP 和建议,在我看来,对 Laravel 不起作用。
<?PHP
return [
/*
|--------------------------------------------------------------------------
| Default Filesystem disk
|--------------------------------------------------------------------------
|
| Here you may specify the default filesystem disk that should be used
| by the framework. The "local" disk,as well as a variety of cloud
| based disks are available to your application. Just store away!
|
*/
'default' => env('FILESYstem_DRIVER','google'),/*
|--------------------------------------------------------------------------
| Default Cloud Filesystem disk
|--------------------------------------------------------------------------
|
| Many applications store files both locally and in the cloud. For this
| reason,you may specify a default "cloud" driver here. This driver
| will be bound as the Cloud disk implementation in the container.
|
*/
// 'cloud' => env('FILESYstem_CLOUD','s3'),'cloud' => 'google',/*
|--------------------------------------------------------------------------
| Filesystem disks
|--------------------------------------------------------------------------
|
| Here you may configure as many filesystem "disks" as you wish,and you
| may even configure multiple disks of the same driver. Defaults have
| been setup for each driver as an example of the required options.
|
| Supported Drivers: "local","ftp","sftp","s3"
|
*/
'disks' => [
'local' => [
'driver' => 'local','root' => storage_path('app'),],'public' => [
'driver' => 'local','root' => storage_path('app/public'),'url' => env('APP_URL').'/storage','visibility' => 'public',// ...
'google' => [
'driver' => 'google','clientId' => env('MAIN_GOOGLE_DRIVE_CLIENT_ID'),'clientSecret' => env('MAIN_GOOGLE_DRIVE_CLIENT_SECRET'),'refreshToken' => env('MAIN_GOOGLE_DRIVE_REFRESH_TOKEN'),'folderId' => env('MAIN_GOOGLE_DRIVE_FOLDER_ID'),// ...
's3' => [
'driver' => 's3','key' => env('AWS_ACCESS_KEY_ID'),'secret' => env('AWS_SECRET_ACCESS_KEY'),'region' => env('AWS_DEFAULT_REGION'),'bucket' => env('AWS_BUCKET'),'url' => env('AWS_URL'),'endpoint' => env('AWS_ENDPOINT'),/*
|--------------------------------------------------------------------------
| Symbolic Links
|--------------------------------------------------------------------------
|
| Here you may configure the symbolic links that will be created when the
| `storage:link` Artisan command is executed. The array keys should be
| the locations of the links and the values should be their targets.
|
*/
'links' => [
public_path('storage') => storage_path('app/public'),];
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)