Login issue in facebook integration

2019-09-16 02:52发布

问题:

I have integrated facebook in ios 6 successfully but i noticed a strange behaviour of the app. Whenever i try to login using facebook everything works fine but when any other user with his/her credentials tries to login, an error shows up. I don't know what's the solution for it.

i am using facebook sdk sample code as reference. For login i am just setting the view frame for login. The protocol implementation for FBLoginView is as follows:

- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView
{
BOOL canShareAnyhow = [FBNativeDialogs canPresentShareDialogWithSession:nil];
// first get the buttons set for login mode
self.postStatusBtn.enabled = YES;
self.shareWithFriendsBtn.enabled = YES;
self.viewFriends.enabled = YES;

}

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                        user:(id<FBGraphUser>)user
{
// here we use helper properties of FBGraphUser to dot-through to first_name and
// id properties of the json response from the server; alternatively we could use
// NSDictionary methods such as objectForKey to get values from the my json object

// setting the profileID property of the FBProfilePictureView instance
// causes the control to fetch and display the profile picture for the user


self.profilePic.profileID = user.id;
self.loggedInUser = user;
NSLog(@"%@",user);

}

- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView
{
BOOL canShareAnyhow = [FBNativeDialogs canPresentShareDialogWithSession:nil];

self.postStatusBtn.enabled = NO;
self.shareWithFriendsBtn.enabled = NO;
self.viewFriends.enabled = NO;
if (!self.viewFriends.enabled)
{
    self.viewFriends.titleLabel.textColor = [UIColor grayColor];
}

if(!self.shareWithFriendsBtn.enabled)
{
    self.shareWithFriendsBtn.titleLabel.textColor = [UIColor grayColor];
}

if (!self.postStatusBtn.enabled)
{
    self.postStatusBtn.titleLabel.textColor = [UIColor grayColor];
}

self.profilePic.profileID = nil;

self.loggedInUser = nil;
}

Thanx in advance...!!

回答1:

I think this will fix your issue:

  1. Go to you Facebook app in your Facebook account.
  2. Click edit your app.
  3. Go to Basic info tab.
  4. Sandbox Mode: check this as Disable
  5. Save the setting.

This will work for you.



回答2:

Have you tried to clear the token when user logs out and someone else login? Following one liner you need to put in where you are logging out the user or user is pressing logout button:

[FBSession.activeSession closeAndClearTokenInformation];

Hope this helps.



回答3:

Use this code

-(IBAction) loginFrmFbBtnPressed:(id)sender
{
    if (FBSession.activeSession.isOpen)
    {
        [self getData];
    } else
    {
        [FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,
                                                                                                 FBSessionState status, NSError *error)
         {
             if (error)
             {
                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                 [alert show];
             }
             else if (FB_ISSESSIONOPENWITHSTATE(status))
             {
                 [self getData];
             }
         }];
    }
}

-(void)getData
{
    if ([FBSession.activeSession.permissions indexOfObject:@"read_stream"] == NSNotFound)
    {
        NSArray *permissions = [[NSArray alloc] initWithObjects:
                                @"read_stream" , nil];
        [FBSession.activeSession reauthorizeWithReadPermissions:permissions completionHandler:^(FBSession *session, NSError *error) {
            if (!error) {
                [self request];
            }
        }];
    }
    else
    {
        [self request];
    }
}

-(void)request
{
    [FBRequestConnection startWithGraphPath:@"me" parameters:[NSDictionary dictionaryWithObject:@"picture,id,birthday,email,name,gender,username" forKey:@"fields"] HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
     {
         [self meRequestResult:result WithError:error];
     }];
}

- (void)meRequestResult:(id)result WithError:(NSError *)error
{
    if ([result isKindOfClass:[NSDictionary class]])
    {
        NSDictionary *dictionary;
        if([result objectForKey:@"data"])
            dictionary = (NSDictionary *)[(NSArray *)[result objectForKey:@"data"] objectAtIndex:0];
        else
            dictionary = (NSDictionary *)result;
        NSLog(@"dictionary : %@",dictionary);
        
        
    }
}