Google Drive and theGoogle Drive SDKBuilding Drive appsClaudio CherubinoGoogle Drive Developer Relations
What is Google Drive?Yea, some marketing :)
Access AnywhereGoogle Drive is everywhere you are -- on theweb, in your home, at the office, and on the go.So wherever you...
Store your files in a safe placeThings happen. Your phone goes for a swim.Your laptop takes an infinite snooze.No matter w...
Powerful searchGoogle Drive can search keywordsin your files -- even the text inpictures -- to help you quickly findwhat y...
View anything                When a coworker shares a file with                you, you may not have the supported        ...
Access to a world of apps!Google Drive works with the apps thatmake you more efficient.Choose from a growing set ofproduct...
Demos!Pixlr EditorHelloFaxAutoCAD WS
Google Drive SDKWhy integrate with Google Drive?
Drive SDK opportunity                                                                 ++        Extensive Reach           ...
Drive SDK featuresDrive●   Create, Read, List, Manage files through the API●   Search, sharing and revisionsDrive Web UI● ...
Integrating with Google DriveGetting Started
Steps for integrating your app w/ DrivePrerequisites:   ●   Create a project in the Google APIs Console   ●   Enable the D...
OAuth 2.0Introduction
A cool tool...                 OAuth 2.0 Playground
Integrating with Google DriveHandling Authorization for Web apps
AuthorizationUsing OAuth 2.0 - Redirecting users to the Grant screen                                                      ...
AuthorizationUsing OAuth 2.0 - Getting back & exchanging the code in your callback handler                                ...
Integrating with Google DriveHandling Authorization for Android
AuthorizationUsing OAuth 2.0 - Using the AccountManagerProblem!Currently not possible: ● Anonymous tokens are not allowed ...
AuthorizationUsing OAuth 2.0 - Using a WebViewSteps to do WebView auth: ● Redirect Users to the grant screen URL in a WebV...
Integrating with Google DriveInteracting w/ Drive files
Instantiating the Drive service Object                                                                                    ...
Creating Files                                                                     Java// Files metadataFile body = new Fi...
Fetching Files                                                                             Java// Getting files metadataFi...
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 integrationPrerequisites:   ●   Create a Chrome Web Store listing       (Painful !)   ●   Instal...
Passing context on open & create    What happens when somebody launches your app from Drive?                              ...
Passing context on open & create    What happens when somebody launches your app from Drive?                              ...
Integrating with Google DriveAdding the Drive Android App Integration
Receiving intents from the Drive app
Receiving intents from the Drive app●   Export an Activity that supports an intent with the following info:      ● action:...
Receiving intents from the Drive app                                                                                      ...
Receiving intents from the Drive app                                                                                      ...
Integrating with Google DriveThe Google Picker
UI Integration - Embedded file picker
Embedding the picker                                                                  JSgoogle.setOnLoadCallback(createPic...
Handling picker selections                                                        JS// A simple callback implementation.fu...
Security and other features
A brief (but important) note on securityThe Drive SDK has 2 security models. ●   The first one gives you full access to th...
A brief (but important) note on securityDrives second security model is a per-file security model●   More restrictive file...
Other Features / tips & tricks ●   Resumable upload & download ●   Indexable text ●   Search! ●   Conversions to native Go...
<Thank You!>http://developers.google.com/driveccherubino@google.comhttp://plus.claudiocherubino.it#ccherubino
google drive and the google drive sdk
google drive and the google drive sdk
Upcoming SlideShare
Loading in …5
×

google drive and the google drive sdk

3,946 views

Published on

Talk di Claudio Cherubino alla DevFest 2012 @ Firenze

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,946
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
51
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

google drive and the google drive sdk

  1. 1. Google Drive and theGoogle Drive SDKBuilding Drive appsClaudio CherubinoGoogle Drive Developer Relations
  2. 2. What is Google Drive?Yea, some marketing :)
  3. 3. Access AnywhereGoogle Drive is everywhere you are -- on theweb, 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
  4. 4. Store your files in a safe placeThings happen. Your phone goes for a swim.Your laptop takes an infinite snooze.No matter what happens to your devices, yourfiles are safely stored in Google Drive.
  5. 5. Powerful searchGoogle Drive can search keywordsin your files -- even the text inpictures -- to help you quickly findwhat youre looking for.
  6. 6. 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.
  7. 7. Access to a world of apps!Google Drive works with the apps thatmake you more efficient.Choose from a growing set ofproductivity applications, integratedright into your Drive.
  8. 8. Demos!Pixlr EditorHelloFaxAutoCAD WS
  9. 9. Google Drive SDKWhy integrate with Google Drive?
  10. 10. Drive SDK opportunity ++ Extensive Reach Effortless Integration Put your app in front of millions of Get the best of Google Drives sharing users with billions of files capabilities, storage capacity and user identity management so you can focus on your app
  11. 11. Drive SDK featuresDrive● Create, Read, List, Manage files through the API● Search, sharing and revisionsDrive Web UI● Open files and docs with your app directly from Drive
  12. 12. Integrating with Google DriveGetting Started
  13. 13. Steps for integrating your app w/ DrivePrerequisites: ● Create a project in the Google APIs Console ● Enable the Drive API ● Create OAuth 2.0 credentialsIntegration steps: ● Auth with OAuth 2.0 [& OpenID Connect] ● Write code for opening / saving / managing files
  14. 14. OAuth 2.0Introduction
  15. 15. A cool tool... OAuth 2.0 Playground
  16. 16. Integrating with Google DriveHandling Authorization for Web apps
  17. 17. AuthorizationUsing OAuth 2.0 - Redirecting users to the Grant screen Java// Instantiating some dependenciesHttpTransport httpTransport = new NetHttpTransport();JacksonFactory jsonFactory = new JacksonFactory();// Building the flow and the redirect URLGoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( httpTransport, jsonFactory, CLIENT_ID, CLIENT_SECRET, SCOPES).build();GoogleAuthorizationCodeRequestUrl urlBuilder = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI);// Redirecting users to the grant screenresp.sendRedirect(urlBuilder.build());
  18. 18. AuthorizationUsing OAuth 2.0 - Getting back & exchanging the code in your callback handler Java// Reading the auth code value from the URLString authorizationCode = req.getParameter("code");// Exchanging the auth code for tokensGoogleTokenResponse tokenResponse = flow.newTokenRequest(authorizationCode).setRedirectUri(REDIRECT_URI).execute();String accessToken = tokenResponse.getAccessToken();String refreshToken = tokenResponse.getRefreshToken();
  19. 19. Integrating with Google DriveHandling Authorization for Android
  20. 20. AuthorizationUsing OAuth 2.0 - Using the AccountManagerProblem!Currently not possible: ● Anonymous tokens are not allowed ● App auth using API Key is Disabled for Drive for security reasonsSolutionsPermanent: Add app auth to auth authentication in Android (available w/ Google Play services!)Temporarily: Use a WebView and trigger an OAuth 2.0 flowCheck this Google IO presentation for more.
  21. 21. AuthorizationUsing OAuth 2.0 - Using a WebViewSteps to do WebView auth: ● Redirect Users to the grant screen URL in a WebView ● Use http://localhost as the redirect URI ● Register a WebViewClient with an onPageStarted method to intercept page change ● Detect successful/failed authorization and read the auth code from the URL of the WebViewResources w/ code samples: ● Sample code for complex login system on mobile apps ● Improved Twitter OAuth for Android
  22. 22. Integrating with Google DriveInteracting w/ Drive files
  23. 23. Instantiating the Drive service Object Java// Building the credentials ObjectGoogleCredentials credentials = flow.createAndStoreCredential(tokenResponse, null);// Here is the Drive serviceDrive service = new Drive.Builder(httpTransport, jsonFactory, credentials);
  24. 24. Creating Files Java// Files metadataFile body = new File();body.setTitle(title);body.setDescription(description);body.setMimeType(mimeType);// Files contentjava.io.File fileContent = new java.io.File(filename);FileContent mediaContent = new FileContent(mimeType, fileContent);// Executing the requestfile = service.files().insert(body, mediaContent).execute();
  25. 25. Fetching Files Java// Getting files metadataFile file = service.files().get(fileId).execute();// Downloading the files contentif (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) { HttpResponse resp = service.getRequestFactory().buildGetRequest( new GenericUrl(file.getDownloadUrl())).execute(); InputStream content = resp.getContent();}
  26. 26. Integrating with Google DriveAdding the Drive Web-UI Integration
  27. 27. UI Integration - "Create"
  28. 28. UI Integration - "Open with"
  29. 29. Distribution - Chrome Web Store
  30. 30. Steps for adding Drive UI integrationPrerequisites: ● Create a Chrome Web Store listing (Painful !) ● Install the application from the CWS ● Enable and configure the Drive SDK in the Google APIs ConsoleIntegration steps: ● Support OAuth 2.0 server-side flow ● Read action and file ID from URL parameter
  31. 31. Passing context on open & create What happens when somebody launches your app from Drive? URLhttps://www.yourapp.com/drive?code=<authorization code>&state=<JSON> JSON{ "action" : "create", "parentId" : "0ADK06pfg" Create actions}{ "action" : "open", "ids" : ["0Bz0bd"] Open actions}
  32. 32. Passing context on open & create What happens when somebody launches your app from Drive? URLhttps://www.yourapp.com/drive?code=<authorization code>&state=<JSON> JSON{ "action" : "open", "exportIds" : ["0Bz0bd"] Open native Google Docs actions}
  33. 33. Integrating with Google DriveAdding the Drive Android App Integration
  34. 34. Receiving intents from the Drive app
  35. 35. Receiving intents from the Drive app● Export an Activity that supports an intent with the following info: ● action: drive.intent.action.DRIVE_OPEN ● path: content://com.google.android.drive/open/resourceId ● type: MIME type of the file● Declare your API Project ID in the Activitys metadata● List supported MIME types in the intent-filter element● The intent will not include the body of the document nor the user account● Retrieve the file from the Drive API using the resourceId provided by the intent in the pathCheck this Google IO presentation for more.
  36. 36. Receiving intents from the Drive app XML<manifest …> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <application …> <activity android:name="DriveActivity" android:label="@string/cloud_paint" android:icon="@drawable/app_icon" android:exported="true"> <meta-data android:name="com.google.android.apps.drive.APP_ID" android:value="id=1234567890" /> <intent-filter> <action android:name="com.google.android.apps.drive.DRIVE_OPEN" /> <data android:mimeType="text/plain" /> <data android:mimeType="text/html" /> </intent-filter> </activity> </application></manifest>
  37. 37. Receiving intents from the Drive app Java@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = getIntent(); final String action = intent.getAction(); if ("drive.intent.action.DRIVE_OPEN".equals(action)) { String fileId = intent.getStringExtra("resourceId"); // Prompt the user to choose the account to use and process the file using the Drive API. } else { // Other action. }}
  38. 38. Integrating with Google DriveThe Google Picker
  39. 39. UI Integration - Embedded file picker
  40. 40. Embedding the picker JSgoogle.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);}
  41. 41. Handling picker selections JS// 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); }}
  42. 42. Security and other features
  43. 43. A brief (but important) note on securityThe Drive SDK has 2 security models. ● The first one gives you full access to the users Drive ○ Read and/or write all files ○ Manage all files ○ List all files ○ ...
  44. 44. A brief (but important) note on securityDrives second security model is a per-file security model● More restrictive file level access● Simple rules - an app can open any file that: ○ The user opened with the app through the Drive UI ○ The user opened with the app through the Picker API ○ The app created itself
  45. 45. Other Features / tips & tricks ● 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 ● Folders ● User Permissions ● Shortcuts ○ Auto-generated MIME type ○ Contentless ○ Indexable & syncable!
  46. 46. <Thank You!>http://developers.google.com/driveccherubino@google.comhttp://plus.claudiocherubino.it#ccherubino

×