4. 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
5. 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.
6. 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.
7. 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.
8. 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.
11. Drive SDK opportunity
++
Extensive Reach Effortless Integration
Put your app in front of millions of Get the best of Google Drive's sharing
users with billions of files capabilities, storage capacity and user
identity management so you can focus
on your app
12. 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
14. 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
18. Authorization
Using OAuth 2.0 - Redirecting users to the Grant screen
Java
// Instantiating some dependencies
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
// Building the flow and the redirect URL
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, jsonFactory, CLIENT_ID, CLIENT_SECRET, SCOPES).build();
GoogleAuthorizationCodeRequestUrl urlBuilder =
flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI);
// Redirecting users to the grant screen
resp.sendRedirect(urlBuilder.build());
19. Authorization
Using OAuth 2.0 - Getting back & exchanging the code in your callback handler
Java
// Reading the auth code value from the URL
String authorizationCode = req.getParameter("code");
// Exchanging the auth code for tokens
GoogleTokenResponse tokenResponse =
flow.newTokenRequest(authorizationCode).setRedirectUri(REDIRECT_URI).execute();
String accessToken = tokenResponse.getAccessToken();
String refreshToken = tokenResponse.getRefreshToken();
21. Authorization
Using OAuth 2.0 - Using the AccountManager
Problem!
Currently not possible:
● Anonymous tokens are not allowed
● App auth using API Key is Disabled for Drive for security reasons
Solutions
Permanent: Add app auth to auth authentication in Android (available w/ Google Play services!)
Temporarily: Use a WebView and trigger an OAuth 2.0 flow
Check this Google IO presentation for more.
22. Authorization
Using OAuth 2.0 - Using a WebView
Steps 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 WebView
Resources w/ code samples:
● Sample code for complex login system on mobile apps
● Improved Twitter OAuth for Android
24. Instantiating the Drive service Object
Java
// Building the credentials Object
GoogleCredentials credentials = flow.createAndStoreCredential(tokenResponse, null);
// Here is the Drive service
Drive service = new Drive.Builder(httpTransport, jsonFactory, credentials);
25. Creating Files
Java
// File's metadata
File body = new File();
body.setTitle(title);
body.setDescription(description);
body.setMimeType(mimeType);
// File's content
java.io.File fileContent = new java.io.File(filename);
FileContent mediaContent = new FileContent(mimeType, fileContent);
// Executing the request
file = service.files().insert(body, mediaContent).execute();
31. 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
32. Passing context on open & create
What happens when somebody launches your app from Drive?
URL
https://www.yourapp.com/drive?code=<authorization code>&state=<JSON>
JSON
{
"action" : "create",
"parentId" : "0ADK06pfg" Create actions
}
{
"action" : "open",
"ids" : ["0Bz0bd"] Open actions
}
33. Passing context on open & create
What happens when somebody launches your app from Drive?
URL
https://www.yourapp.com/drive?code=<authorization code>&state=<JSON>
JSON
{
"action" : "open",
"exportIds" : ["0Bz0bd"] Open native Google Docs actions
}
36. 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 Activity's 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 path
Check this Google IO presentation for more.
38. Receiving intents from the Drive app
Java
@Override
protected 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.
}
}
44. A brief (but important) note on security
The Drive SDK has 2 security models.
● The first one gives you full access to the user's Drive
○ Read and/or write all files
○ Manage all files
○ List all files
○ ...
45. A brief (but important) note on security
Drive's 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
46. 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!