Google Drive & Google Drive SDK

Post on 06-May-2015

1.289 views 0 download

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

Google Drive and the

Google Drive SDKBuilding Drive apps

Abdelhalim Lagrid

Google Developer Group, Algiers

1

Introduction :

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

What is Google Drive?Yea, some marketing :)

2222

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

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.

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.

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.

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.

Google Drive SDKWhy integrate with Google Drive?

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

++

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

Integrating with Google DriveGetting Started

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

OAuth 2.0Introduction

A cool tool...

OAuth 2.0 Playground

Integrating with Google DriveHandling Authorization for Web apps

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())

Integrating with Google DriveInteracting with Drive files

Python

Instantiating the Drive service Object

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

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']

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']

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()

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

Integrating with Google DriveAdding the Drive Web-UI Integration

UI Integration - "Create"

UI Integration - "Open with"

Distribution - Chrome Web Store

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

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

Integrating with Google DriveThe Google Picker

UI Integration - Embedded file picker

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);}

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); }}

Other features

• 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

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

h.lagrid@gmail.com