In our earlier blog, we told about “How to Create, Upload & Delete a Google Doc using Scala“. But the Google Docs that were created, had private access (by default), i.e., only the creator of Google Doc can access it.
So, now we continue to add one more feature to it i.e., to Create a Public Google Doc using Google Drive API in Scala. With this feature we can make our Google Docs public so, that anyone can read them but not modify them.
To add this feature, follow these steps:
1. Import following package to create a variable of type Permission().
2. Get the access token to access your drive
val access_token = "Your Drive's Access Token"
3. Set the mimeType (type of Google Doc) of your Google Doc
val mimeType = "mimeType"
MimeType can be Document/Spreadsheet/Presentation.
4. At last create the public Google Doc using following code
val service = prepareGoogleDrive(access_token) val body = new File body.setMimeType(mimeType) body.setTitle("Untitled Google Doc") val file = service.files.insert(body).execute val permission = new Permission() permission.setRole("reader") permission.setType("anyone") permission.setValue("me") service.permissions().insert(file.getId(), permission).execute()
For more information on different access levels of Google Docs, click here.