GithubHelp home page GithubHelp logo

jquery-gdrive's Introduction

JQuery Plugin for Google Drive API

Google Drive is a nice and easy (once you get used to it) way to store and share files on the cloud. Apps on Android phones and tablets synchronize their documents and images to Google Drive. One can think of so many interesting applications using them.

Such applications often need to let the user choose files and folders from their Google Drive, read their contents and do something useful. This simple JQuery plugin provides APIs for some often used operations.

Setting up jquery-gdrive

  • Download the file jquery-gdrive.js and include it in your HTML.
  • Include the following code snippet in your HTML (after modifying it appropriately of course):
    
 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
 <script src="//apis.google.com/js/client.js"></script>
 <script src="jquery-gdrive.js"></script>
 <script type="text/javascript">
   $(document).ready(function() {
     $().gdrive('init', {
       'devkey': 'YOUR GOOGLE DEVELOPMENT KEY HERE',
       'appid': 'YOUR GOOGLE APPLICATION ID HERE'
 });
 </script>

Authenticating to Google

The plugin handles authentications and authorizations required from Google. The user is prompted for permissions on first use (in a session). The application can retrieve the authenticated user id and access token as below:

// returns the user id (e-mail) which is signed in.
user_id = $().gdrive('user')

// returns the authorization token
auth_tok = $().gdrive('token')

If authentication is delegated to be done by jquery-gdrive, any additional authentication scopes required by the application can be provided through the init call using the scope option (similar to how devkey and appid are supplied).

If authorization is done by the application instead, the results can be shared with jquery-gdrive through the init call using options authtok (for authorization token) and user (for authorized email id).

Selecting Files and Folders

jquery-plugin uses Google Drive picker API to display a file picker dialog. Selection made in the file picker can be populated in an HTML element or returned via a callback.

Configure HTML elements that should hold selected Google Drive files using something similar to the snippet below.

// gdrive_file is the HTML elelemt that will hold the selection result
$('#gdrive_file').gdrive('set', {

	// Trigger is the HTML element which on clicking should show the picker 
	// (defaults to the same element that hosts the result)
	'trigger': 'gdrive_file_selector', 
	
	// Text to show as header of the picker dialog
	'header': 'Select a file',
	
	// File/folder types to be shown and selected.
	// Use 'application/vnd.google-apps.folder' for folder.
	// Complete list here: https://developers.google.com/drive/web/mime-types
	// Defaults to showing all.
	'filter': ''
});

The selected files are assigned an URL with a custom gdrive scheme with format gdrive://<file_name>/<file_id>.

Try it

Try the API with a sample implementation here.

Or download the repository, run any simple static file web server, e.g. python -m SimpleHTTPServer 8080 to start a simple web server, point your browser to http://localhost:8080/

TODO

  • read/write/modify files
  • create folders
  • events

jquery-gdrive's People

Contributors

tanmaykm avatar

Watchers

James Cloos avatar Olanipekun Femi avatar

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.