首先需要查询文件。在响应中,您希望在名为“edit media”的链接列表中查找元素。然后你把邮件寄到那个地址。
下面的代码可以从谷歌客户端API的网站添加到谷歌的示例项目docs-v3-atom-oauth-sample中。
http://code.google.com/p/google-api-java-client/wiki/GoogleAPIs
private String queryRegistryforEditId() {
String str ="https://docs.google.com/feeds/default/private/full?title=" + URL_FRIENDLY_QUERY_PHRASE;
DocsUrl url = new DocsUrl(str);
DocumentListFeed feed;
try {
feed = DocumentListFeed.executeGet(transport, url);
} catch (IOException e) {
e.printStackTrace();
return null;
}
//display(feed);
String ans = null;
//LIST OF FILES MATCHING QUERY
for (DocumentListEntry doc : feed.docs) {
//doc.content.src has url to download file
//I added src to content class that comes from the sameple code
Map<String, String> data = retriveDocUsingId(doc.content.src);
List<Link> lik = doc.links;
for (Link i : lik) {
//look for "edit-media" to get url to post edits to file
if (i.rel.equals("edit-media")) {
ans = i.href;
System.out.println(i.href);
}
}
//System.out.println(" doc.title: " + doc.title + " doc.id " + doc.id);
}
return ans;
}
private void updateDocumentText(String edit) {
HttpRequest request = transport.buildPutRequest();
request.url = new GoogleUrl(edit);
GoogleHeaders headers = (GoogleHeaders)transport.defaultHeaders;
headers.contentType = "text/plain";
headers.gdataVersion = "3";
headers.slug = "examplefile";
headers.ifMatch = "*";
request.headers = headers;
AtomParser parser = new AtomParser();
parser.namespaceDictionary = Namespace.DICTIONARY;
transport.addParser(parser);
File file = new File ("/newfilepath/test233.txt");
InputStreamContent bContent = new InputStreamContent();
bContent.type = "text/plain";
request.content = bContent;
try {
bContent.setFileInput(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
com.google.api.client.http.HttpResponse res2;
try {
res2 = request.execute();
System.out.println(res2.parseAsString());
} catch (HttpResponseException e) {
try {
System.out.println(e.response.parseAsString());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}