繁体   English   中英

使用自定义按钮和FBSession登录时如何获取用户数据

[英]How to get user data when using custom button and FBSession for login

我正在为FBLogin使用自定义按钮实现,而不是使用FBLoginView类。 根据文档,我在按钮的IBAction中实现了FBSession方法:

// If the session state is any of the two "open" states when the button is clicked
if (FBSession.activeSession.state == FBSessionStateOpen
    || FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {

    // Close the session and remove the access token from the cache
    // The session state handler (in the app delegate) will be called automatically
    [FBSession.activeSession closeAndClearTokenInformation];

    // If the session state is not any of the two "open" states when the button is clicked
} else {
    // Open a session showing the user the login UI
    // You must ALWAYS ask for public_profile permissions when opening a session
    [FBSession openActiveSessionWithReadPermissions:@[@"public_profile"]
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {

         // Retrieve the app delegate
         AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
         // Call the app delegate's sessionStateChanged:state:error method to handle session state changes
         [appDelegate sessionStateChanged:session state:state error:error];
     }];
}

现在,当我在FBLoginView Delegate中获取用户数据时:

-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
NSLog(@"user info %@", user);}

用户向我提供了所有我的辅助数据,例如用户的名字和姓氏,电子邮件ID等。我希望从Custom UI实现中获得类似的对象。 我该如何实现?

[[FBRequest requestForMe] startWithCompletionHandler:
          ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
              if (!error) {
                  NSLog(@"accesstoken %@",[NSString stringWithFormat:@"%@",session.accessTokenData]);
                  NSLog(@"user id %@",user.id);
                  NSLog(@"Email %@",[user objectForKey:@"email"]);
                  NSLog(@"User Name %@",user.username);
              }
          }];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM