Java 使用管理访问权限导出/下载演示文稿和电子表格模拟其他域用户
我需要导出/下载其他域用户的所有文件。我使用客户端登录管理帐户来查看域用户的所有文件。但是,只有文档可以导出/下载,其他文档无法导出/下载 那么其他的下载url格式(文件、pdf、演示文稿和电子表格)是什么 我的文档下载url是Java 使用管理访问权限导出/下载演示文稿和电子表格模拟其他域用户,java,google-docs,google-docs-api,Java,Google Docs,Google Docs Api,我需要导出/下载其他域用户的所有文件。我使用客户端登录管理帐户来查看域用户的所有文件。但是,只有文档可以导出/下载,其他文档无法导出/下载 那么其他的下载url格式(文件、pdf、演示文稿和电子表格)是什么 我的文档下载url是 https://docs.google.com/feeds/download/documents/Export?xoauth_requestor=admin@domain.com&docId=<id>&exportFormat=doc }不
https://docs.google.com/feeds/download/documents/Export?xoauth_requestor=admin@domain.com&docId=<id>&exportFormat=doc
}不要手动构建下载链接,而是使用条目的内容链接,如文档中所述:
如果不手动构建下载链接,我将得到异常“无验证头信息”。但是,文件类型“文件”和“文件”可以正常下载。
public class AuthExample {
private static DocsService docService = new DocsService("Auth Example");
public static void main(String[] args)
throws Exception
{
String adminUser = admin;
String adminPassword = adminpasswd;
String impersonatedUser = "user@domain.com";
docService.setUserCredentials(adminUser, adminPassword);
URL url = new URL( "https://docs.google.com/feeds/" + impersonatedUser + "/private/full");
DocumentListFeed feed = docService.getFeed(url, DocumentListFeed.class);
for (DocumentListEntry entry : feed.getEntries()) {
String title = entry.getTitle().getPlainText();
System.out.println( title );
String type = entry.getType();
if ( type.equals("document") )
{
String encodedAdminUser = URLEncoder.encode(adminUser);
String resourceId = entry.getResourceId();
String resourceIdNoPrefix = resourceId.substring( resourceId.indexOf(':')+1 );
String downloadUrl =
"https://docs.google.com/feeds/download/documents/Export" +
"?xoauth_requestor=" + encodedAdminUser +
"&docId=" + resourceIdNoPrefix +
"&exportFormat=doc";
downloadFile( downloadUrl, title + ".doc" );
}
}
}
// Method pasted directly from Google documentation
public static void downloadFile(String exportUrl, String filepath)
throws IOException, MalformedURLException, ServiceException
{
System.out.println("Exporting document from: " + exportUrl);
MediaContent mc = new MediaContent();
mc.setUri(exportUrl);
MediaSource ms = docService.getMedia(mc);
InputStream inStream = null;
FileOutputStream outStream = null;
try {
inStream = ms.getInputStream();
outStream = new FileOutputStream(filepath);
int c;
while ((c = inStream.read()) != -1) {
outStream.write(c);
}
} finally {
if (inStream != null) {
inStream.close();
}
if (outStream != null) {
outStream.flush();
outStream.close();
}
}
}