如何将我的应用集成到iOS中的facebook
应用中? like this screen(jasper app)
答案 0 :(得分:1)
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
//Download facebook from facebook developer site and implement the following methods.
-(void)doLoginInFacebook:(UIViewController *)viewController
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
[login setLoginBehavior:FBSDKLoginBehaviorSystemAccount];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
//NSLog(@"Error===%@",error);
}
else if (result.isCancelled)
{
// Handle cancellations
}
else
{
//NSLog(@"result is:%@",result);
if ([result.grantedPermissions containsObject:@"email"])
{
[self fetchUserInfoWithViewController:viewController];
}
else
{
[self fetchUserInfoWithViewController:viewController];
}
}
}];
}
-(void)fetchUserInfoWithViewController:(UIViewController *)ViewController
{
if ([FBSDKAccessToken currentAccessToken])
{
//NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSMutableDictionary *dic=result;
//NSLog(@"%@",dic);
if (self.delegate && [self.delegate respondsToSelector:@selector(doGetFacebookUserInfo:)] )
{
[self.delegate doGetFacebookUserInfo:dic];
}
}
else
{
// [self.delegate doGetFacebookUserInfo:nil];
//NSLog(@"Error %@",error);
}
}];
}
}
答案 1 :(得分:0)