Created
December 29, 2015 07:44
-
-
Save saurabh23july/a4045379e50a2fa13977 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface ViewController () | |
{ | |
NSString *name; | |
NSString *email ; | |
NSString *acessToken; | |
} | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
} | |
- (void)viewWillAppear:(BOOL)animated | |
{ | |
[super viewWillAppear:YES]; | |
UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 200, 50)]; | |
nameLabel.text = name; | |
nameLabel.textColor = [UIColor blackColor]; | |
[self.view addSubview:nameLabel]; | |
UILabel *emailLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 150, 200, 50)]; | |
emailLabel.text = email; | |
[self.view addSubview:emailLabel]; | |
UILabel *accessTokenLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 200, 200, 50)]; | |
accessTokenLabel.text = acessToken; | |
[self.view addSubview:accessTokenLabel]; | |
UIButton *myLoginButton=[UIButton buttonWithType:UIButtonTypeCustom]; | |
myLoginButton.backgroundColor=[UIColor darkGrayColor]; | |
myLoginButton.frame=CGRectMake(0,0,300,40); | |
myLoginButton.center = self.view.center; | |
[myLoginButton setTitle: @"My Login Button" forState: UIControlStateNormal]; | |
[myLoginButton addTarget:self | |
action:@selector(loginButtonClicked) forControlEvents:UIControlEventTouchUpInside]; | |
[self.view addSubview:myLoginButton]; | |
} | |
-(void)loginButtonClicked | |
{ | |
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; | |
[login | |
logInWithReadPermissions: @[@"public_profile",@"user_friends",@"email"] | |
fromViewController:self | |
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { | |
if (error) { | |
NSLog(@"Process error"); | |
} else if (result.isCancelled) { | |
NSLog(@"Cancelled"); | |
} else { | |
NSLog(@"Logged in"); | |
NSLog(@"Result %@",result); | |
} | |
}]; | |
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] | |
initWithGraphPath:@"/me" | |
parameters:@{ @"fields": @"id,name,email"} | |
HTTPMethod:@"GET"]; | |
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { | |
NSLog(@"resds %@",result); | |
name = [result valueForKey:@"name"]; | |
email = [result valueForKey:@"email"]; | |
acessToken = [result valueForKey:@"id"]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment