0

我已经实现了 FB 登录,但从未收到回调...在 .plist 中,我确实添加了 FacebookAppID 和 FacebookDisplayName

这是我的代码。它是我问题中的所有相关代码

-(IBAction)btnLoginWithFBClick:(id)sender {

    _session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];
    [_session resume];

    if (![_session isConnected]) {
        _loginDialog = nil;
        _loginDialog = [[FBLoginDialog alloc] init];
        _loginDialog.delegate = self;
        [_loginDialog show];
    }
    else {
        NSLog(@"logado");



- (void)dialogDidSucceed:(FBDialog *)dialog {
    if ([dialog isMemberOfClass:[FBLoginDialog class]]) {
        NSLog(@"[FBLoginDialog::dialogDidSucceed] just did succeed");
    } else if ([dialog isMemberOfClass:[FBPermissionDialog class]]) {
        NSLog(@"[FBPermissionDialog::dialogDidSucceed] update user status");
       // [self facebookUpdateUserStatus];
    }
}

- (void)session:(FBSession*)session didLogin:(FBUID)uid {
    [self getFacebookName];
    [_loginDialog setHidden:YES];
}

- (void)session:(FBSession*)session willLogout:(FBUID)uid {
    //_logoutButton.hidden = YES;
    _facebookName = nil;
}

- (void)getFacebookName {
    NSString* fql = [NSString stringWithFormat:
                     @"select uid,name, email, sex, pic from user where uid == %lld", _session.uid];
    NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
    [[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
}

- (void)dialogCompleteWithUrl:(NSURL *)url {
    if (![[url absoluteString] isEqualToString:@"fbconnect://success#="]) { // your msg
        NSLog(@"ae");
  }
} 


- (void)request:(FBRequest*)request didLoad:(id)result {

    if ([request.method isEqualToString:@"facebook.fql.query"]) {
        NSArray* users = result;
        NSDictionary* user = [users objectAtIndex:0];
        NSLog(@"Usuario facebook: %@", user);
        NSString *identifier = [user objectForKey:@"uid"];
        NSString *name = [user objectForKey:@"name"];
        NSString *email = [user objectForKey:@"email"];
        NSString *sex = [user objectForKey:@"sex"];
     }
}

我已经在 Facebook 应用程序中设置了 Apple Id、Bundle id 等,我确实在谷歌上寻找解决方案,但没有任何效果......知道吗?

4

1 回答 1

1

使用 FBLoginView 进行 Facebook 登录,将 FBLoginView 添加到您的视图中。实现 FBLoginViewDelegate 方法,如。

-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {

 //do what you want when login is successfull.

  }

//注销你可以简单地弹出到你添加了FBLoginview的视图

//或者你可以调用这个方法来注销并弹出来查看你想要的

- (void)closeSession {

    [FBSession.activeSession closeAndClearTokenInformation];

}

// 也将此方法添加到您的 appdelegate

 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{

        // FBSample logic
        // We need to handle URLs by passing them to FBSession in order 
        // for SSO authentication to work.

       return [FBSession.activeSession handleOpenURL:url];


    }
于 2013-06-28T12:10:51.897 回答