2013-02-19 49 views
0

我已经成功将Facebook集成到了ios 6中,但我注意到了应用程序的一个奇怪的行为。 每当我尝试使用Facebook登录时,一切正常,但当任何其他用户使用他/她的凭据尝试登录时,会显示错误。我不知道它有什么解决方案。在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; 
} 

Thanx提前...!

+0

可能是权限,在这里发布您的FBLoginView代码,那么我们将能够帮助您更多。 – 2013-02-19 09:23:21

+0

请张贴一些代码或张贴错误:) – Rushabh 2013-02-19 09:31:42

+0

你正在得到什么错误? – 2013-02-19 13:27:31

回答

3

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

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

这将为你工作。

+0

Thanx哥们它为我工作....... :) – daemon22 2013-02-20 07:42:31

+3

@jatt我没有得到编辑和沙箱选项在Facebook开发者 – user100 2014-05-23 10:34:41

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); 
        
        
   } 
} 
+0

thnx fr d代码,但我使用Facebook sdk示例代码作为参考。 这将是gr8,如果你可以帮我那个... – daemon22 2013-02-19 11:14:40

1

您是否尝试过当用户注销时清除令牌和别人登录?下面的一个班轮,你需要把你在哪里注销用户或用户正在按注销按钮:

[FBSession.activeSession closeAndClearTokenInformation]; 

希望这会有所帮助。

+0

nope仍然是它的d相同的错误.. !!! – daemon22 2013-02-19 13:57:57

+0

删除bulid,清理所有目标,然后再次运行构建并在注销按钮中添加上面的行。 – 2013-02-19 14:01:16

+0

这样做后我仍然得到相同的错误...... – daemon22 2013-02-19 14:10:09