how can i get user information using facebook sdk 4.1 in ios? -
i'm using pre-built login uibutton of version 2.3 of facebook integration.
problem: getting null result, when fetching user details.
-(void) loginbutton:(fbsdkloginbutton *)loginbutton didcompletewithresult:(fbsdkloginmanagerloginresult *)result error:(nserror *)error { if ([fbsdkaccesstoken currentaccesstoken]) { fbsdkgraphrequest *request =[[fbsdkgraphrequest alloc]initwithgraphpath:@"me" parameters:nil]; [request startwithcompletionhandler:^(fbsdkgraphrequestconnection *connection, id result, nserror *error) { // handle result nslog(@"%@",result); }]; fbsdkprofile *profile = [[fbsdkprofile alloc]init]; } }
try code:
appdelegate.m
- (void)applicationdidbecomeactive:(uiapplication *)application { [fbsdkappevents activateapp]; //default fb button [[nsnotificationcenter defaultcenter]postnotificationname:@"getfacebookdata" object:nil]; } - (bool)application:(uiapplication *)application openurl:(nsurl *)url sourceapplication:(nsstring *)sourceapplication annotation:(id)annotation { return [[fbsdkapplicationdelegate sharedinstance] application:application openurl:url sourceapplication:sourceapplication annotation:annotation]; }
viewdidload of viewcontroller
[[nsnotificationcenter defaultcenter]addobserver:self selector:@selector(getfacebookdata) name:@"getfacebookdata" object:nil]; fbsdkloginbutton *loginbutton = [[fbsdkloginbutton alloc] init]; loginbutton.center = self.view.center; [self.view addsubview:loginbutton];
add method in view controller
- (void)getfacebookdata{ if ([fbsdkaccesstoken currentaccesstoken]) { [[[fbsdkgraphrequest alloc] initwithgraphpath:@"me" parameters:@{@"fields": @"first_name, last_name, picture.type(large), email, name, id, gender"}] startwithcompletionhandler:^(fbsdkgraphrequestconnection *connection, id result, nserror *error) { if (!error) { nslog(@"fetched user:%@", result); } }]; } }
Comments
Post a Comment