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?
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"]);
}
Ah nevermind, it works. I had to use @"me"
in [facebook requestWithGraphPath: @"me" andDelegate: self];
instead of the URL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With