hanumanDev
hanumanDev

Reputation: 6614

Getting Facebook username for iOS

I'm using the following to get the Facebook username:

    [facebook requestWithGraphPath:@"me" andDelegate:facebook];

from my understanding I then have to use something like the following request to

  - (void)request:(FBRequest *)request didLoad:(id)result {

  NSLog(@"Result: %@", result);
  NSDictionary *userInfo = (NSDictionary *)result;
  userName = [userInfo objectForKey:@"name"];
  fb_id = [userInfo objectForKey:@"id"];
  }

my question is how do I call this request method from another method?

thanks for any help

Upvotes: 0

Views: 1544

Answers (1)

Malek_Jundi
Malek_Jundi

Reputation: 6160

check my function below to fetch user data id,pic and name

- (void)fetchUserDetails {
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"SELECT uid, name, pic FROM user WHERE uid=me()", @"query",nil];

    [fb requestWithMethodName:@"fql.query"
                                     andParams:params
                                 andHttpMethod:@"POST"
                                   andDelegate:self];


}

and in the delegate method you will log the name like this

- (void)request:(FBRequest *)request didLoad:(id)result 
{
    if ([result isKindOfClass:[NSArray class]] && [result count]>0) {
            result = [result objectAtIndex:0];
   }
   if ([result objectForKey:@"name"]) 
            NSString *userName = [result objectForKey:@"name"];

   NSLog(@"%@",userName);
}

Upvotes: 1

Related Questions