DocsService client = new DocsService("service name");
client.setUserCredentials(username,password);
File file = new File(filename);
URL url = new URL("https://docs.google.com/feeds/default/private/full/?ocr=true&convert=true");
String mimeType = DocumentListEntry.MediaType.fromFileName(file.getName()).getMimeType();
DocumentEntry newDocument = new DocumentEntry();
newDocument.setTitle(new PlainTextConstruct(file.getName()));
newDocument.setMediaSource(new MediaFileSource(file, mimeType));
//newDocument.setFile(file, mimeType);
newDocument = client.insert(url, newDocument);
System.out.println("uploaded "+file.getName());
JOptionPane.showMessageDialog(null, "uploaded "+file.getName(), "alert", JOptionPane.ERROR_MESSAGE);
使用此代码我上传文件,但该文件作为文档上传。意味着我上传任何类型的文件作为文档上传到谷歌驱动器