iOS 第三方登陆 —— FaceBook

来源:互联网 发布:网络歌星人气排名 编辑:程序博客网 时间:2024/05/17 12:21

1、注册成为开发者:https://developers.facebook.com/

2、下载FacebookSDK安装包,默认安装路径为:~/Documents/FacebookSDK

3、导入FBSDKCoreKit.framework和FBSDKLoginKit.framework

4、点击gettingstarted,进行plist和 URLSchemes配置,以及AppDelegate.m中的配置






5、在登录界面导入

#import <FBSDKCoreKit/FBSDKCoreKit.h>

#import <FBSDKLoginKit/FBSDKLoginKit.h>

6、获取token

    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];    [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {        if (error) {            // Process error        } else if (result.isCancelled) {            // Handle cancellations        } else {            // If you ask for multiple permissions at once, you            // should check if specific permissions missing            NSLog(@"token = %@",result.token.tokenString);            if (result.token.tokenString!=nil) {                [self loginWithFaceBookToken:result.token.tokenString];            }            if ([result.grantedPermissions containsObject:@"email"]) {                // Do work            }        }    }];




0 0
原创粉丝点击