How to create folder with the latest API?

15 views
Skip to first unread message

peeInMyPantz

unread,
Nov 18, 2008, 9:51:19 PM11/18/08
to Google Data APIs Objective-C Client Library Discussion
Hi,

I'm trying to create folder with the new API without success. Are
there any sample available for this?

Greg Robbins

unread,
Nov 19, 2008, 10:48:04 PM11/19/08
to gdata-objec...@googlegroups.com
The docs server seems to be requiring that the posted folder entry have a label in its category, though the server shouldn't require that.

Here's a sample that works:

  GDataEntryFolderDoc *docEntry = [GDataEntryFolderDoc documentEntry];

  // add a category that includes a "folder" label to work around the server issue
  GDataCategory *category = [GDataCategory categoryWithScheme:kGDataCategoryScheme
                                                         term:kGDataCategoryFolderDoc];
  [docEntry setCategories:[NSArray arrayWithObject:category]];
  [category setLabel:@"folder"];
 
  [docEntry setTitleWithString:@"My New Folder"];

  NSURL *postURL = [[docListFeed postLink] URL];
 
  [service fetchDocEntryByInsertingEntry:docEntry
                              forFeedURL:postURL
                                delegate:self
                       didFinishSelector:@selector(createFolderTicket:finishedWithEntry:)
                         didFailSelector:@selector(createFolderTicket:failedWithError:)];

honcheng

unread,
Nov 19, 2008, 11:00:14 PM11/19/08
to gdata-objec...@googlegroups.com
Looks like I left out category, and I was looking out for something
that looks like setLabel.

Thanks

Greg Robbins

unread,
Nov 20, 2008, 1:00:40 AM11/20/08
to gdata-objec...@googlegroups.com
The library includes a category in the entry returned by [GDataEntryFolderDoc documentEntry], but that category lacks a label (as the server really should not require a label.)

honcheng

unread,
Nov 20, 2008, 2:26:58 AM11/20/08
to gdata-objec...@googlegroups.com
Thanks.

At the moment, is it possible to create folders and upload spreadsheet directly to the folder? Or do I have upload the spreadsheet separately and move it into the folder?

Greg Robbins

unread,
Nov 20, 2008, 2:39:53 AM11/20/08
to gdata-objec...@googlegroups.com
I would guess that you can insert a new entry directly into a folder's feed, but I have not tried it.

Brandon

unread,
Nov 23, 2008, 12:51:31 AM11/23/08
to Google Data APIs Objective-C Client Library Discussion
On Nov 19, 11:39 pm, Greg Robbins <grobb...@google.com> wrote:
> I would guess that you can insert a new entry directly into a folder's feed,
> but I have not tried it.

I've tried inserting an entry into a folder feed's post and self
links. If I use the post link neither the success nor failure
selectors get called. Trying the self link gets me into the failure
selector with a 400 error and the logs show "Invalid Request URI". I'm
not sure what to try next.

Greg Robbins

unread,
Nov 23, 2008, 2:09:48 AM11/23/08
to gdata-objec...@googlegroups.com
I just tried fetching a folder's feed, then uploading a new document directly into the folder, and it worked fine.

Here's the code I used to upload to the folder's feed:

NSURL *postURL = [[folderFeed postLink] URL];

GDataEntryDocBase *docEntry = [GDataEntryStandardDoc documentEntry];
[docEntry setTitleWithString:@"new file"];
[docEntry setUploadData:[@"abcdefg" dataUsingEncoding:NSUTF8StringEncoding]];
[docEntry setUploadMIMEType:@"text/plain"];
[docEntry setUploadSlug:@"newfile.txt"];

ticket = [service fetchDocEntryByInsertingEntry:docEntry
  forFeedURL:postURL
  delegate:self
  didFinishSelector:@selector(uploadToFolderTicket:finishedWithEntry:)
  didFailSelector:@selector(uploadToFolderTicket:failedWithError:)];

If neither the success nor failure selector is called, then I suspect there's an error in your code, as one or the other should always be called (unless the ticket returned is nil, indicating that the server fetch couldn't be done.)

Brandon

unread,
Nov 23, 2008, 5:09:59 PM11/23/08
to Google Data APIs Objective-C Client Library Discussion
I tried your code and I'm getting a nil ticket. I did a copy/paste, so
I'm guessing the error has to be in my code for fetching the folder's
feed. But I thought I had that part figured out already.

For test purposes, I get a list of folders and then pick the first one
returned. Using that entry's selfLink I fetch the folder's feed, which
calls testTicket:finishedWithFeed:, which contains the code you posted
above. Everything appears to work up to that point. But, the insert
request then returns a nil ticket.

Here's the callback for the folder list request...

- (void) folderListTicket:(GDataServiceTicket *)ticket
finishedWithFeed:(GDataFeedDocList *)object
{
for( GDataEntryDocBase *doc in [object entries] )
{
NSString* name = [[doc title] stringValue];
NSLog(@"name = %@", name);

// Fetch the folder's feed object
GDataServiceTicket* ticket = [appDelegate.docService
fetchDocsFeedWithURL:[[doc selfLink] URL]
delegate:self
didFinishSelector:@selector(testTicket:finishedWithFeed:)
didFailSelector:@selector(ticket:failedWithError:)];
return; // Use only the first matching entry
}
}

Greg Robbins

unread,
Nov 23, 2008, 8:01:35 PM11/23/08
to gdata-objec...@googlegroups.com
The self link for a folder entry (or for any other entry) gets a fresh copy of the entry, not the folder's feed. You can get the folder feed from the folder entry's content element:

  NSString *folderFeedURI = [[folderEntry content] sourceURI];
  if (folderFeedURI != nil) {
    NSURL *folderFeedURL = [NSURL URLWithString:folderFeedURI];
  ...

Getting a nil ticket back is really unusual. Set a breakpoint in GDataServiceBase's fetchObjectWithURL: method to figure out what's happening. My guess is that you're trying to post into a entry, which lacks a post link, rather than into a feed and hence the "feed post URL" passed to the fetch call is nil.

I've also updated the DocsSample on top-of-trunk in the project's svn repository to show how to move documents in and out of a folder feed.

Brandon

unread,
Nov 24, 2008, 6:21:07 PM11/24/08
to Google Data APIs Objective-C Client Library Discussion
On Nov 23, 5:01 pm, Greg Robbins <grobb...@google.com> wrote:
> The self link for a folder entry (or for any other entry) gets a fresh copy
> of the entry, not the folder's feed. You can get the folder feed from the
> folder entry's content element:

Ah, that's where I was going wrong. I must need to take a closer look
at the protocol, because these things just aren't obvious to me yet.
Thanks.

> Getting a nil ticket back is really unusual. Set a breakpoint in
> GDataServiceBase's fetchObjectWithURL: method to figure out what's
> happening. My guess is that you're trying to post into a entry, which lacks
> a post link, rather than into a feed and hence the "feed post URL" passed to
> the fetch call is nil.

That was exactly the problem. Good catch.

> I've also updated the DocsSample on top-of-trunk in the project's svn
> repository to show how to move documents in and out of a folder feed.

I'll take a look. Thanks.
Reply all
Reply to author
Forward
0 new messages