Google Drive & Google Drive SDK

38

description

This presentation will help you to know more about Google Drive and Google Drive SDK , so you can use the API in several Applications .

Transcript of Google Drive & Google Drive SDK

Page 1: Google Drive & Google Drive SDK
Page 2: Google Drive & Google Drive SDK

Google Drive and the

Google Drive SDKBuilding Drive apps

Abdelhalim Lagrid

Google Developer Group, Algiers

1

Page 3: Google Drive & Google Drive SDK

Introduction :

One of Cloud google’s products : lunched in 2012 ..known by Google Drive API .

Page 4: Google Drive & Google Drive SDK

What is Google Drive?Yea, some marketing :)

2222

Page 5: Google Drive & Google Drive SDK

Access Anywhere

Google Drive is everywhere you are -- on the web, in your home, at the office, and on the go.

So wherever you are, your stuff is just...there. Ready to go, ready to share.

Install it on:

PC, Mac, Android, iOS

Page 6: Google Drive & Google Drive SDK

Store your files in a safe place

Things happen. Your phone goes for a swim. Your laptop takes an infinite snooze.

No matter what happens to your devices, your files are safely stored in Google Drive.

Page 7: Google Drive & Google Drive SDK

Powerful search

Google Drive can search keywords in your files -- even the text in pictures -- to help you quickly find what you're looking for.

Page 8: Google Drive & Google Drive SDK

View anything

When a coworker shares a file with you, you may not have the supported software on your computer. With Google Drive you can open and view over 35 file types directly in the browser.

Page 9: Google Drive & Google Drive SDK

Access to a world of apps!

Google Drive works with the apps that make you more efficient.

Choose from a growing set of productivity applications, integrated right into your Drive.

Page 10: Google Drive & Google Drive SDK

Google Drive SDKWhy integrate with Google Drive?

Page 11: Google Drive & Google Drive SDK

Drive SDK opportunity

Extensive Reach Effortless Integration

Put your app in front of millions of users with billions of files

Get the best of Google Drive's sharing capabilities, storage capacity and user identity management so you can focus on your app

++

Page 12: Google Drive & Google Drive SDK

Drive SDK features

Drive• Create, Read, List, Manage files through the API

• Search, sharing and revisions

Drive Web UI• Open files and docs with your app directly from Drive

Page 13: Google Drive & Google Drive SDK

Integrating with Google DriveGetting Started

Page 14: Google Drive & Google Drive SDK

Steps for integrating your app w/ Drive

Prerequisites:• Create a project in the Google APIs Console

• Enable the Drive API

• Create OAuth 2.0 credentials

Integration steps:• Auth with OAuth 2.0 [& OpenID Connect]

• Write code for opening / saving / managing files

Page 15: Google Drive & Google Drive SDK

OAuth 2.0Introduction

Page 16: Google Drive & Google Drive SDK

A cool tool...

OAuth 2.0 Playground

Page 17: Google Drive & Google Drive SDK

Integrating with Google DriveHandling Authorization for Web apps

Page 18: Google Drive & Google Drive SDK

Python

AuthorizationUsing OAuth 2.0 - Redirecting users to the Grant screen

decorator = OAuth2Decorator(client_id=settings.CLIENT_ID, client_secret=settings.CLIENT_SECRET, scope=settings.SCOPE, user_agent='we-cloud')class Documents(webapp.RequestHandler): @decorator.oauth_required def get(self): user = users.get_current_user() if user: service = build('drive', 'v2', http=decorator.http())

Page 19: Google Drive & Google Drive SDK

Integrating with Google DriveInteracting with Drive files

Page 20: Google Drive & Google Drive SDK

Python

Instantiating the Drive service Object

# Here is the Drive serviceservice = build('drive', 'v2', http=decorator.http())

Page 21: Google Drive & Google Drive SDK

Python

Creating Folders

folder = { 'title': self.request.get('project[name]'), 'mimeType': 'application/vnd.google-apps.folder' } created_folder = service.files().insert(body=folder).execute() projectcollectionid = created_folder['id']

Page 22: Google Drive & Google Drive SDK

Python

Creating Files

mimetype = 'application/vnd.google-apps.' + self.request.get('doc[type]') document = { 'title': self.request.get('doc[name]'), 'mimeType': mimetype } if projectcollectionid: document['parents'] = [{'id': projectcollectionid}] created_document = service.files().insert(body=document).execute() resourceid = created_document['id']

Page 23: Google Drive & Google Drive SDK

Python

Sharing Files

#Share the file with other members new_permission = { 'value': email, 'type': 'user', 'role': 'writer' } service.permissions().insert(fileId=fileid, body=new_permission).execute()

Page 24: Google Drive & Google Drive SDK

Python

Searching for files

def retrieve_all_files(service,query): result = [] page_token = None param = {} param['q'] = "fullText contains '"+ query + "'" param['fields'] = "items(id,parents/id)" while True: try: if page_token: param['pageToken'] = page_token files = service.files().list(**param).execute() result.extend(files['items']) page_token = files.get('nextPageToken') if not page_token: break except errors.HttpError, error: print 'An error occurred: %s' % error break return result

Page 25: Google Drive & Google Drive SDK

Integrating with Google DriveAdding the Drive Web-UI Integration

Page 26: Google Drive & Google Drive SDK

UI Integration - "Create"

Page 27: Google Drive & Google Drive SDK

UI Integration - "Open with"

Page 28: Google Drive & Google Drive SDK

Distribution - Chrome Web Store

Page 29: Google Drive & Google Drive SDK

Steps for adding Drive UI integration

Prerequisites:• Create a Chrome Web Store listing (Painful !)

• Install the application from the CWS

• Enable and configure the Drive SDK in the Google APIs Console

Integration steps:• Support OAuth 2.0 server-side flow

• Read action and file ID from URL parameter

Page 30: Google Drive & Google Drive SDK

JSON

Passing context on open & createWhat happens when somebody launches your app from Drive?

{ "action" : "create", "parentId" : "0ADK06pfg"

}

{ "action" : "open", "ids" : ["0Bz0bd"]

}

URL

https://www.yourapp.com/drive?code=<authorization code>&state=<JSON>

Create actions

Open actions

Page 31: Google Drive & Google Drive SDK

Integrating with Google DriveThe Google Picker

Page 32: Google Drive & Google Drive SDK

UI Integration - Embedded file picker

Page 33: Google Drive & Google Drive SDK

JS

Embedding the picker

google.setOnLoadCallback(createPicker);google.load('picker', '1');

var view = new google.picker.View(google.picker.ViewId.DOCS);view.setMimeTypes("image/png,image/jpeg,image/jpg");

function createPicker() { picker = new google.picker.PickerBuilder() .enableFeature(google.picker.Feature.MULTISELECT_ENABLED) .setAppId(YOUR_APP_ID) .addView(view) .setCallback(pickerCallback) .build(); picker.setVisible(true);}

Page 34: Google Drive & Google Drive SDK

JS

Handling picker selections

// A simple callback implementation.function pickerCallback(data) { if (data.action == google.picker.Action.PICKED) { var fileId = data.docs[0].id; alert('The user selected: ' + fileId); }}

Page 35: Google Drive & Google Drive SDK

Other features

Page 36: Google Drive & Google Drive SDK

• Resumable upload & download• Indexable text• Search!• Conversions to native Google Documents• Export of native Google Documents in many formats• OCR• Revisions• List installed apps• Copy files, Trash files, Touch files• User Permissions• Shortcuts

o Auto-generated MIME typeo Contentless

Other Features / tips & tricks

Page 37: Google Drive & Google Drive SDK

<Thank You!>http://developers.google.com/drive

[email protected]

Page 38: Google Drive & Google Drive SDK