Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get email address using facebook sdk for IOS and graph api for facebook

I am trying to get the email address from a user. He logs in, I ask permission to access email and he chooses ok. Then I use the graph API from facebook to access the email address.


- (void) fbDidLogin
{
  btnLogin.isLoggedIn = TRUE;
  [btnLogin updateImage];

  NSString *theURL = 
  [ [NSString stringWithFormat: 
    @"https://graph.facebook.com/me?access_token=%@", facebook.accessToken
    ]stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding
  ];

  NSLog(@"%@", theURL);
  [facebook requestWithGraphPath: theURL andDelegate: self];
}

...

- (void)request:(FBRequest*)request didLoadRawResponse:(NSData*)data
{
  NSString *response = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
  NSLog(@"%@", response);
  [response release];
}

This is how i get the information:


- (void) request:(FBRequest*)request didLoad:(id)result
{
  if ([result isKindOfClass:[NSDictionary class]])
  {
    NSString *email = [result objectForKey: @"email"];
    NSString *name = [result objectForKey: @"name"];
    NSString *facebookId = [result objectForKey: @"id"];
    //...
  }
}

It gives me only this string: { id = "https://graph.facebook.com/me"; } What did I do wrong?

like image 775
gyozo kudor Avatar asked Sep 23 '10 09:09

gyozo kudor


2 Answers

I found answer:

 NSArray *permissions = [[NSArray alloc] initWithObjects:@"user_likes",@"offline_access",@"read_stream",@"publish_stream",@"email",nil];

  [facebook requestWithGraphPath:@"me"andParams:params andDelegate:self];
  -(void)facebookLoginScreen:(NSDictionary *)result
   {
        NSLog(%@,[result objectForKey:@"email"]);
   }
like image 193
Hemant Dixit Avatar answered Nov 14 '22 23:11

Hemant Dixit


Ah nevermind, it works. I had to use @"me" in [facebook requestWithGraphPath: @"me" andDelegate: self]; instead of the URL.

like image 43
gyozo kudor Avatar answered Nov 14 '22 23:11

gyozo kudor