Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/w99910/php-google-drive
Easy-To-Use PHP Library For Google Drive
https://github.com/w99910/php-google-drive
Last synced: 2 months ago
JSON representation
Easy-To-Use PHP Library For Google Drive
- Host: GitHub
- URL: https://github.com/w99910/php-google-drive
- Owner: w99910
- License: mit
- Created: 2022-09-19T09:18:08.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-13T06:06:29.000Z (6 months ago)
- Last Synced: 2024-11-16T17:49:21.024Z (2 months ago)
- Language: PHP
- Size: 16.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Easy-To-Use PHP Library For Google Drive
- ## Installation
```bash
$ composer require zlt/php-google-drive
```- ## Setup
```php
$clientId = 'clientId';
$clientSecret = 'clientSecret';
$refreshToken = 'refreshToken';
$config = new GoogleDriveConfig(clientId: $clientId, clientSecret: $clientSecret, refreshToken: $refreshToken);
$service = new GoogleDriveService($config);
```> If you don't know how to find the credentials i.e, clientId, clientSecret, refreshToken, read [here](https://github.com/ivanvermeyen/laravel-google-drive-demo/blob/master/README.md#create-your-google-drive-api-keys).
- ## Usage
- ### Creating Content
Use `put` method which accepts three parameters:
- `content` - contents to be stored
- `fileName` - filename of content to be stored
- `dir` - If not specified, file will be stored under root. Otherwise, file will be stored under specifed dir.
```php
$service->put('This is example text', 'example.txt');
$service->put('This is text will be stored under specified dir','example.txt','12sdf_sdfjopwoeriupsdf')
```- ### Getting File
Use `get` method which accepts two parameters and return `Google\Drive\DriveFile` or `GuzzleHttp\Psr7\Response`
- `fileName` - filename of content to be stored
- `params` - If not specified, empty array is passed.
```php
$service->get('xxxxxxxxxxxxx');// or
$service->get('xxxxxxxxxxxxx', [
// pass parameters
])
```- ### Getting File Content
Use `getContent` method which return `GuzzleHttp\Psr7\Response`.
- `fileName` - filename of content to be stored
```php
$service->getContent('xxxxxxxxxxxxx');
```- ### Creating Dir
Use `makeDirectory` which accepts two parameters:
- `folderName` - folderName
- `dir` - If not specified, folder will be created under root. Otherwise, folder will be created under specifed dir.
```php
$service->makeDirectory('New Folder');
$service->makeDirectory('New Folder Under Specified Dir','12sdf_sdfjopwoeriupsdf')
```- ### Copy File
Use `copy` which accepts three parameters:
- `fromId` - fileId
- `fileName` - fileName
- `dir` - If not specified, folder will be created under root. Otherwise, folder will be created under specifed dir.
```php
$service->copy('1kojo32uoiuo123','new file.txt');
$service->copy('1kojo32uoiuo123','new file.txt','12sdf_sdfjopwoeriupsdf')
```- ### List Contents
Use `listContents` method which accepts two parameters: `path` which is either pathId, fileName, folderName
,and `recursive` which decide to show children contents.
```php
// List files inside root dir.
$service->listContents()
// List files inside 'shared with me' folder.
$service->listContents(Zlt\PhpGoogleDrive\GoogleDriveService::SharedWithMe);
```- ### List Directories
Use `directories` method which accepts two parameters: `path` which is either pathId, fileName, folderName
```php
// List files inside root dir.
$service->directories()
// List files inside 'shared with me' folder.
$service->directories(Zlt\PhpGoogleDrive\GoogleDriveService::SharedWithMe);
```- ### List Files
Use `files` method which accepts two parameters: `path` which is either pathId, fileName, folderName
```php
// List files inside root dir.
$service->files()
// List files inside 'shared with me' folder.
$service->files(Zlt\PhpGoogleDrive\GoogleDriveService::SharedWithMe);
```- ### Delete File or Folder
Delete file
```php
$service->delete('fileId')
```