I had written the below code for fblogin :
FBSDKLoginManager *fblogin = [[FBSDKLoginManager alloc] init];
[fblogin logInWithReadPermissions:params fromViewController:viewController handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error) {
// Show process error from facebook
NSLog(@"Process error");
completion(nil,error);
} else if (result.isCancelled) {
/// At time of done and cancel event
NSLog(@"Cancelled");
completion(nil,error);
} else {
/// This action come at least one permission allowed user
NSLog(@"Logged in");
completion(result,error);
}
}];
To fetch the user detail The code which i had written is :
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"picture.type(large), email,birthday,name,gender,first_name, last_name,bio, invitable_friends"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
if(!error)
{
completion(result,error);
}
else
{
completion(nil,error);
}
}];
After user login. I am trying to fetch the friendlist (only if) user click invite friend button.
To fetch the friend list the code which i use to fetch friendlist :
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"/me/invitable_friends?limit=5000"
parameters:@{@"fields": @"name,first_name, last_name,invitable_friends"}
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
NSLog(@"result==>%@",result);
}];
I am getting proper friend list from the above code. Issue is When i quit my application and reopen the application and then try to fetch the friend list again it give me error.
Error which i am getting is :
Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=An active access token must be used to query information about the current user., com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2500, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 2500;
"fbtrace_id" = BrC8am8ChZ6;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}}
I had solved this by writing the below line in my appdelegate:
[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
I got this answer from below link : Reliable check for active session on app startup in Facebook iOS SDK v4.0
Thank you SO