Search code examples
google-docs-apigoogle-drive-api

Google docs 3.0 java API upload file is not working properly


I just downloaded newsest doc list api, and have a try. My code as below:

DocsService client = new DocsService("testappv3");
client.setUserCredentials("username", "password");
File file = new File("c:/test.txt");
URL url = new URL("https://docs.google.com/feeds/defaults/private/full/");
String mimeType = DocumentListEntry.MediaType.fromFileName(file.getName()).getMimeType();
DocumentEntry newDocument = new DocumentEntry();
newDocument.setTitle(new PlainTextConstruct("test"));
//newDocument.setMediaSource(new MediaFileSource(file, mimeType));
newDocument.setFile(file, mimeType);
newDocument = client.insert(url, newDocument);

the error is below:

com.google.gdata.util.ResourceNotFoundException: Not Found
<HTML>
<HEAD>
<TITLE>Not Found</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Not Found</H1>
<H2>Error 404</H2>
</BODY>
</HTML>

Solution

  • Your URI is incorrect:

    https://docs.google.com/feeds/defaults/private/full/
    

    Should be

    https://docs.google.com/feeds/default/private/full/
    

    (with no s)