google drive api laravel

  api, google-api, laravel

{ "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Login Required" } }

GOOGLE_CLIENT_ID=458149355420-p1aj58dq7is4j9bqlfig21l6qbc7uhml.apps.googleusercontent.com

GOOGLE_CLIENT_SECRET=IsY0PF_ZW6Rm7SEtIciIZ-BD
GOOGLE_DRIVE_REFRESH=4/0AY0e-g6g9CFaHtE1Qyo5pa5SoUjvJI57V-iTnjQz8WUqr0TXhmeoMMdsmn9i7NnTfzTbyA
GOOGLE_DRIVE_FOLDER_ID=1MTeZiLnZLryyMdJ5-dT0O3KJGM8DHOpU

'google'=>[
        'driver'=>'google',
        'clientId'=>env("GOOGLE_CLIENT_ID"),
        'clientSecret'=>env("GOOGLE_CLIENT_SECRET"),
        'refreshToken' =>env("GOOGLE_DRIVE_REFRESH"),
        'folderId'=>env("GOOGLE_DRIVE_FOLDER_ID"),
    ],

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 GoogleDriveAdapter($service, $config['folderId']);
        return new Filesystem($adapter);

    });

Source: Laravel

Leave a Reply