Integrating with Google Drive UI will give an edge to your product and ease your users’ life. Users can interact with your product right from the Drive interface. Hooks within Drive application enable 3rd party developers to integrate the proprietary product and perform actions on the document, media stored on the Drive. But there seems to be a little challenge. Though Google Drive API documentation is comprehensive, the dots are not well connected. I received an email from one of my reader who was struggling with integration. With this article, I thought of listing the steps, so the community can benefit from it.
Before I directly jump on the topic of Drive integration, I would like you to go through my previous articles which lay down detailed steps about how to setup Spring boot project and configuration Google OAuth for authorization.
- Google Drive Setup (http://www.carbonrider.com/2018/09/05/google-drive-api-video-tutorial/)
- OAuth Setup (http://www.carbonrider.com/2018/09/11/google-developer-console-project-setup-oauth/)
- Google Drive And Spring Boot integration (http://www.carbonrider.com/2018/10/08/google-drive-api-integration-with-spring-boot/)
You will find that there are other articles as well, but to integrate with Google Drive UI, we require only the steps listed in the above article.
Request for Scope
Once you are able to set up the project, make sure that you modify the scope variable and it should include additional scope for Drive install. The scope definition in JAVA will look like following
List SCOPES = Arrays.asList(DriveScopes.DRIVE, “https://www.googleapis.com/auth/drive.install”);
If this scope is not present while requesting authorization from the user, your product will not be available to the user. The best option to verify whether the scope has been included is to verify OAuth screen
Unless this scope is not explicitly granted by the user, the application will not be visible in the Google Drive. If you click the information icon next to the scope, you will see the additional details.
Apart from requesting scope at the time of authorization, you will have to configure the following additional steps in the Google Developer Console.
The option to brand your application with Application Name, description, icon, etc can be configured using the “Drive UI Integration” option available in console. Along with these options, you must also configure the file association for your product. Check the following screenshot which displays how mime-type and file extension has been configured. Your application will only be available for these extensions.
Google will use this configuration to feature your product only when the associated file is selected by a user for some action (open, create, etc)
You will find that there are two different URL configuration required – To create a new file and URL to open a file. These URL must be hosted on the publicly accessible domain for production usage. For development mode, you can leverage *.nip.io domain as shown in the above screenshot.
Each of the URL will receive file id or metadata required to perform the operation.
If you are unsure, why the user is not able to see your product in their Drive UI, please refer to the following steps.
Check if the user is able to see the Application listed in the context menu of Google Drive (it should be either available for “txt” file type or for creating new document). Note the file type depends on the configuration you have done in the developers console.
The drive settings section also indicates the list of applications having access to the Drive. Ensure that the “Use by default” option is checked.
Google Account Settings – Security
This is one more area, wherein user should see your product having access to their Drive.
Click “Manage third-party access link” to see the detailed information about the scopes that have been granted to the application. Note the second line which indicates “Add itself to Google Drive”. The line indicates that the application has been granted Google Drive UI access.
Once you are able to see your application is listed in the Google Drive UI, you should be able to use all the APIs that we discussed in the previous article. Here is the list of few of them.
- File operations – http://www.carbonrider.com/2018/11/25/file-operation-google-drive-api/
- Folder Operations – http://www.carbonrider.com/2018/11/27/folder-operations-on-google-drive/