我使用的代码
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 basic_info permissions when opening a session [FBSession openActiveSessionWithReadPermissions:@[@"basic_info,email"] 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]; }]; }
从这个代码我需要获取用户名和邮件ID.如果有人知道解决方案,请提前感谢.
解决方法
使用以下代码
FBSession *session = [[FBSession alloc] initWithPermissions:@[@"basic_info",@"email"]]; [FBSession setActiveSession:session]; [session openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session,FBSessionState status,NSError *error) { if (FBSession.activeSession.isOpen) { [[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); } }]; } }];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。