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 1l2A2iNm5_4uX6VZ9HVncaIRd-YXBZZ0FS0W-1U7UJ08
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.