ios – 如何获取Facebook SDK的用户名和电子邮件ID?

ios – 如何获取Facebook SDK的用户名和电子邮件ID?,第1张

概述我使用的代码 if (FBSession.activeSession.state == FBSessionStateOpen || FBSession.activeSession.state == FBSessionStateOpenTokenExtended) { // Close the session and remove the access token 我使用的代码
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);                         }                     }];                }            }];
总结

以上是内存溢出为你收集整理的ios – 如何获取Facebook SDK的用户名和电子邮件ID?全部内容,希望文章能够帮你解决ios – 如何获取Facebook SDK的用户名和电子邮件ID?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1113277.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存