问题
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