views:

102

answers:

2

Fetching http://graph.facebook.com/514417 from the Facebook Graph API gives me the NSString @"http://www.facebook.com/mattdipasquale". How do I extract just mattdipasquale every time? Can I assume the link will be the same format every time? In that case, I could just do:

NSString *fbUsername = [[result valueForKey:@"link"] substringFromIndex:24];

That works, but it seems kinda brittle. Do you recommend a better way?

Thanks!

Matt

A: 

How about:

NSString *fbUsername = [[result valueForKey:@"link"] lastPathComponent];
MattDiPasquale
Thanks! That's exactly what I wanted. You're pretty damn smart!
MattDiPasquale
What? You are asking a question and answering it yourself (that's fine) and then you compliment yourself as well
vodkhang
@Matt: +1 for the funny comment :P
Po
+1  A: 

Using fb api for iOS should be easier

  NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                  @"SELECT name FROM user WHERE uid=<your user id>", @"query",
                                  nil];
  [_facebook requestWithMethodName: @"fql.query" 
                         andParams: params
                     andHttpMethod: @"POST" 
                       andDelegate: self]; 

Should get you formal name.

Martha
What you give is FQL, and what is in the question is Graph API. They are different kinds of API of FB
vodkhang
That's true, just to give another option that i get as easier, at least for getting user public data.
Martha
Yes, I'm using `facebook-ios-sdk`, except I'm doing: `[fb requestWithGraphPath:@"me" andDelegate:self];` because I also want other data. Anyway, that call returns the `link: "http://www.facebook.com/mattdipasquale"` data. Is this more efficient than fql? I figured they`d optimize it since it's a common request. Thanks for your answer though because it may come in handy if I want to do more customized requests in the future.
MattDiPasquale