Create, Upload & Delete Google Docs using Play Scala application

Table of contents
Reading Time: 2 minutes

This blog talks about creating, uploading & deleting Google Docs using a Play Scala application. We have used oauth2 in order to communicate with the Google Drive to perform various Google Doc operations. Let us see the process step by step.

1.First integrate Google Drive infrastructure in your Play Scala Application. You can read about it from here to know how to do it.

2. Then in order to use Google Drive, first you have to prepare it. Now, to prepare it you have add this code.

Here you have to pass the Access Token for accessing the Google Drive.

3. Then to Create a new Google Doc add this code.

Here you have to pass the Access Token (code) and the type (mimeType) of Google Doc which you want to create. The type of Google Doc can be Document/Spreadsheet/Presentation.

4. To Upload a file from your Hard Disk to Google Drive add this code.

Here you have to pass Access Token, file to upload, file name and content type which you want to upload to Google Drive

5. At last to Delete a Google Doc add this code.

In here you to pass Access token and Doc Id in order to delete it from Google Drive. Document Id is present in Document Url. For Example, if your Google Doc URL is this https://docs.google.com/a/knoldus.com/document/d/1l2A2iNm5 _4uX6VZ9HVncaIRd-YXBZZ0FS0W-1U7UJ08/ then the document id is .

Note :- In case of Google Spreadsheet Doc Id is key. For example if the spreadsheet’s URL is this https: //docs.google.com/a/knoldus.com/spreadsheet/ccc?key=0AiZ5C9Yq7QMUdG84X3V1M1pNMlRvM0xnNldVSzRSa3c&usp=drive then doc Id is 0AiZ5C9Yq7QMUdG84X3V1M1pNMlRvM0xnNldVSzRSa3c. So, while deleting a spreadsheet from Google Docs pass this key as Doc Id to the function given above.

Written by 

Himanshu Gupta is a software architect having more than 9 years of experience. He is always keen to learn new technologies. He not only likes programming languages but Data Analytics too. He has sound knowledge of "Machine Learning" and "Pattern Recognition". He believes that best result comes when everyone works as a team. He likes listening to Coding ,music, watch movies, and read science fiction books in his free time.

1 thought on “Create, Upload & Delete Google Docs using Play Scala application3 min read

Comments are closed.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading