Created
March 21, 2022 18:50
-
-
Save GaetanoPiazzolla/5ec3e3e913a8e51794697ee0a4098b95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.api.services.drive.model.Permission; | |
import com.google.api.services.drive.model.PermissionList; | |
import java.io.IOException; | |
import java.security.GeneralSecurityException; | |
public boolean publishForm(String formId, String token) throws GeneralSecurityException, IOException { | |
PermissionList list = driveService.permissions().list(formId).setOauthToken(token).execute(); | |
if (list.getPermissions().stream().filter((it) -> it.getRole().equals("reader")).findAny().isEmpty()) { | |
Permission body = new Permission(); | |
body.setRole("reader"); | |
body.setType("anyone"); | |
driveService.permissions().create(formId, body).setOauthToken(token).execute(); | |
return true; | |
} | |
return false; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment