Rename a folder / Collection with Google Documents List Data API v3.0

561 Views Asked by At

I am trying to rename a collection, but I get the error But

com.google.gdata.util.InvalidEntryException: Invalid request URI

, this is the code that I have

DocsService client = new DocsService("test testApp v1");

     URL feedUrl = new URL("https://docs.google.com/feeds/default/private/full/folder%3A"+IDFOLDER);

     DocumentListEntry newEntry = new FolderEntry();
     newEntry.setId(IDFOLDER);
     newEntry.setTitle(new PlainTextConstruct(newName));
     client.insert(feedUrl, newEntry);

This is the way to do that or what i have wrong ?

1

There are 1 best solutions below

1
On

Renaming a collection (or a document entry) is similar to retrieving the entry from the API, changing the title and sending an update (PUT) request to the document entry's edit URL. You can use this code snippet to accomplish that in Java:

static DocumentListEntry renameDocument(DocsService client, String resourceUrl, 
    String newTitle) throws MalformedURLException, IOException, 
    ServiceException {
  DocumentListEntry entry =  client.getEntry(
      new URL(resourceUrl), DocumentListEntry.class);

  entry.setTitle(new PlainTextConstruct(newTitle));
  DocumentListEntry updatedEntry =  client.update(
      new URL(entry.getEditLink().getHref()), entry);
  // Check that updatedEntry has the new title.
  return updatedEntry;
}