Java - Google API - Publish a document

跟風遠走 提交于 2019-12-01 11:20:10

问题


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:


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);


来源:https://stackoverflow.com/questions/8084338/java-google-api-publish-a-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!