Java - Google API - Publish a document

2019-02-20 11:28发布

I have a problem uploading information using the Google Document API. The task is to upload a document, then publish it right after the upload. The first part I have solved, get a DocsService client, authenticate myself with client.setUserCredentials(userName, password) method, and then upload the content with client.insert(URL, newDocument).

At this point the document appears in my Google folder. My problem is I can't figure out how too publish it. I tried to emulate the POST method (what Google creates when I click publish), but it didn't work. I also tried to use this methodology, but I could not figure out how should I authenticate myself (using client.setUserCredentials).

Is there any simple way, or best practice for publishing via the API?

1条回答
地球回转人心会变
2楼-- · 2019-02-20 12:07

Sharing is done by modifying the document's ACL, more information can be found in the developer's guide.

Using the Java client library, to make a document read-only for everybody, you can do:

AclEntry aclEntry = new AclEntry();
aclEntry.setRole(AclRole.READER);
aclEntry.setScope(new AclScope(AclScope.Type.DEFAULT, null));
URL url = new URL(documentEntry.getAclFeedLink().getHref);

return service.insert(url, aclEntry);
查看更多
登录 后发表回答