Try it.
-(IBAction)CLK_ConnectWithFB:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
login.loginBehavior = FBSDKLoginBehaviorNative;
[login logInWithReadPermissions:@[@"email", @"user_friends",@"user_posts"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
NSLog(@"error is :%@",error);
}
else if (result.isCancelled)
{
NSLog(@"error is :%@",error);
}
else
{
if ([result.grantedPermissions containsObject:@"email"])
{
[self fetchUserInfo];
[login logOut];
}
}
}];
}
-(void)fetchUserInfo
{
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id,name,link,first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown ,posts, friendlists"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSLog(@"result is :%@",result);
NSLog(@"friend is :%@",[[result valueForKey:@"friends"]objectForKey:@"data"]);
NSString *photostring=[[[result valueForKey:@"picture"] objectForKey:@"data"] valueForKey:@"url"];
photostring = [photostring stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];
}
}];
}
}
source
share