Java-Google API-发布文档 [英] Java - Google API - Publish a document
问题描述
我在使用Google Document API上传信息时遇到问题.任务是上传文档,然后在上传后立即发布.我已经解决的第一部分,获得一个DocsService
客户端,使用client.setUserCredentials(userName, password)
方法进行身份验证,然后使用client.insert(URL, newDocument)
上传内容.
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)
.
这时,文档显示在我的Google文件夹中.我的问题是我无法弄清楚它的发布方式.我尝试模拟POST方法(单击发布"时Google创建的方法),但没有用.我还尝试使用此方法,但我可以不知道我应该如何验证自己(使用client.setUserCredentials
).
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
).
通过API发布是否有任何简单的方法或最佳实践?
Is there any simple way, or best practice for publishing via the API?
推荐答案
Sharing is done by modifying the document's ACL, more information can be found in the developer's guide.
使用Java客户端库,使每个人都对文档只读,您可以执行以下操作:
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);
这篇关于Java-Google API-发布文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!