Skip to content

Instantly share code, notes, and snippets.

@saurabh23july
Created December 29, 2015 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saurabh23july/a4045379e50a2fa13977 to your computer and use it in GitHub Desktop.
Save saurabh23july/a4045379e50a2fa13977 to your computer and use it in GitHub Desktop.
@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