如何解决刷新令牌必须传入或设置为 setAccessToken 的一部分 Laravel
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 举报,一经查实,本站将立刻删除。