Code Monkey home page Code Monkey logo

easy-google-drive-api-php's Introduction

Easy Google Drive API PHP

Fast and easy to use Google Drive API for PHP.

  • Include class file.
  • Complete the basic setup.
  • Magic

Features (v0.1)

  • Easy to setup;
  • Create Folders,Upload files,List files or folders by just calling simple function.

(v0.2) (15/08/2017)

  • Refresh Token added for long lived session
  • isLoggedIn() method added to check access token is available without accessing session variables

Installation

Clone this repo.

Install the dependencies of GoogleAPI by using composer.

$ composer install

How to use

Open your favorite Terminal and run these commands.

Open GoogleClient.php and set your credintial details

protected $client_id = '<CLIENT_ID>';
protected $client_secret = '<CLIENT_SECRET>';
protected $redirect_uri = '<REDIRECTED_URI>';

Authentication:

require_once 'google.php'; // Include Class File
session_start(); //Start the session
$google = new GoogleClient(); //Create GoogleClient Object

// Check if the user is logged in
if(!$google->isLoggedIn()){ 
    // Go to Google Login Page
	header('Location: '.$google->getAuthURL());
	exit;
}

// If the page is redirected from google authentication
if(isset($_GET['code'])){
    // Authenticate and start the session
	$google->authenticate($_GET['code']);
	# your code ..
}

Drive Operations

Always initlize drive before using Drive operation

$google->initDriveService();

Create Folder

/**
 *  Create folder at google drive
 *  @param string $parentId folder id in which folder will be created
 *  @param string $folderName folder name to create
 *  @return string id of created folder
 */
$folderId = $google->createFolder($parentFolderId,$folderName);

Upload File

 /**
  *  Upload file to given folder
  *  @param string $parentId parent folder in which folder will be upload
  *  @param string $filePath file local path of file which will be upload
  *  @param string $fileName file name of the uploaded copy at google drive
  *  @return string id of uploaded file
 */
    $fileId uploadFile($parentId,$filePath,$fileName="none");

List Files and Folders

/**
 *  Get the list of files or folders or both from given folder or root
 *  @param string $search complete or partial name of file or folder to search
 *  @param string $parentId parent folder id or root from which the list of files or folders or both will be generated
 *  @param string $type='all' file or folder (files,folders or all)
 *  @return array list of files or folders or both from given parent directory
 */
$list = listFilesFolders($search,$parentId,$type='all');

Todos

  • More ease to use API.
  • Different options of credentials either by initilizing variables or secred.json file.
  • Features like moving and copying one folder to another folder.

easy-google-drive-api-php's People

Contributors

dharmin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

easy-google-drive-api-php's Issues

large file upload

hi bro, first of all
API works very well.
But I can't upload 1GB - 2GB Files over 50mb, why?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.