0

我已成功将 facebook 集成到 ios 6 中,但我注意到该应用程序的一个奇怪行为。每当我尝试使用 facebook 登录时,一切正常,但是当任何其他具有他/她凭据的用户尝试登录时,就会出现错误。我不知道它的解决方案是什么。

我正在使用 facebook sdk 示例代码作为参考。对于登录,我只是设置登录的视图框架。FBLoginView 的协议实现如下:

- (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;
}

提前谢谢...!!

4

3 回答 3

3

我认为这将解决您的问题:

  1. 在您的 Facebook 帐户中访问您的 Facebook 应用程序。
  2. 单击编辑您的应用程序。
  3. 转到基本信息选项卡。
  4. 沙盒模式: 选中此项为禁用
  5. 保存设置。

这对你有用。

于 2013-02-20T05:00:21.523 回答
1

当用户注销并且其他人登录时,您是否尝试过清除令牌?在一行之后,您需要在您要注销用户或用户正在按下注销按钮的位置放置:

[FBSession.activeSession closeAndClearTokenInformation];

希望这可以帮助。

于 2013-02-19T13:33:08.727 回答
0

使用此代码

-(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);
        
        
    }
}
于 2013-02-19T09:38:45.467 回答