0

I need to export/download all files of the other domain users. I used the client login with administer account to see the all files of domain users. however,only document can be export/download,others are fail.

so what is the download url format of the others(For File,pdf,presentation and spreadsheet)??

my document download url is

https://docs.google.com/feeds/download/documents/Export?xoauth_requestor=admin@domain.com&docId=<id>&exportFormat=doc

my program is as following:

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();
    }
}
}

}

Kenny Lin
  • 13
  • 2

1 Answers1

0

Don't build the download link manually, instead use the entry's content link as explained in the docs:

https://developers.google.com/google-apps/documents-list/#downloading_documents_and_files

Claudio Cherubino
  • 14,896
  • 1
  • 35
  • 42
  • if don't build download link manually, I will get the exception "No authentication header information". however, the doc type "file" and "document" can be download normally. – Kenny Lin Jun 04 '12 at 01:30