Facebook 登录集成(笔记)

记录Facebook 登录集成

忽略注册账号、新建应用步骤

1.按FB官方文档集成

Facebook 登录集成(笔记)_第1张图片
Paste_Image.png

2.登录、获取用户名

#import 
#import 
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logOut];//避免出现 FBSDK Login Error Code: 308
    [login logInWithReadPermissions: @[@"public_profile",@"email"] 
fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, 
NSError *error) {
         if (error) {
             NSLog(@"Process error");
         } else if (result.isCancelled) {
             NSLog(@"Cancelled");
         } else {
             NSLog(@"Logged in");
             NSDictionary*params=[NSDictionary new];
             FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                           initWithGraphPath:result.token.userID
                                           parameters:params
                                           HTTPMethod:@"GET"];
             [request 
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                                   id result,
                                                   NSError *error) {
                 NSString*name=[result objectForKey:@"name"];
                 NSString*userid=[result objectForKey:@"id"];
              
                 NSLog(@"name=%@ userID=%@ ",name,userid);
             }];      
         }
     }];

遇到的问题

1.没有按FB的文档正确集成导致权限问题

解决方法重新按照FB的文档对比每一步

2.FBSDK Login Error Code: 308 错误

参考了 http://stackoverflow.com/questions/30643122/ios-parse-facebook-login-error-308-fbsdkloginbadchallengestring/31480026#31480026
在执行logInWithReadPermissions 之前调用

 [login logOut];

你可能感兴趣的:(Facebook 登录集成(笔记))