I am quite new to objective-C and iPhone Development environment.
I am implementing Facebook login in my app to get User\'s name, Email and profile Picture. I have s
Hope This could Help You ..
- (IBAction)Loginwithfacebookaction:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
[login logInWithReadPermissions:@[@"public_profile"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error)
{
NSLog(@"Process error");
}
else if (result.isCancelled)
{
NSLog(@"Cancelled");
}
else
{
[self getFacebookProfileInfos];
}
}];
}
- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error {
NSLog(@"Received error %@ and auth object %@",error, auth);
if (!error)
{
email =signIn.userEmail;
[[NSUserDefaults standardUserDefaults] setObject:email forKey:@"useremail"];
NSLog(@"Received error and auth object %@",signIn.userEmail);
NSLog(@"Received error and auth object %@",signIn.userID);
if ( auth.userEmail)
{
[[[GPPSignIn sharedInstance] plusService] executeQuery:[GTLQueryPlus queryForPeopleGetWithUserId:@"me"] completionHandler:^(GTLServiceTicket *ticket, GTLPlusPerson *person, NSError *error)
{
// this is for fetch profile image
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",person.image.url]];
NSLog(@"%@",url);
name= person.displayName;
[[NSUserDefaults standardUserDefaults] setObject:name forKey:@"userNameLogin"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"Name:%@",person.displayName);
[self callWebserviceToUploadImage];
}];
}
}
}
-(void)getFacebookProfileInfos {
FBSDKGraphRequest *requestMe = [[FBSDKGraphRequest alloc]initWithGraphPath:@"/me?fields=first_name, last_name, picture, email" parameters:nil];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
[connection addRequest:requestMe completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if(result)
{
if ([result objectForKey:@"email"]) {
email = [result objectForKey:@"email"];
[[NSUserDefaults standardUserDefaults] setObject:email forKey:@"useremail"];
}
if ([result objectForKey:@"first_name"]) {
NSLog(@"First Name : %@",[result objectForKey:@"first_name"]);
name = [result objectForKey:@"first_name"];
[[NSUserDefaults standardUserDefaults] setObject:name forKey:@"userNameLogin"];
}
if ([result objectForKey:@"id"])
{
NSLog(@"User id : %@",[result objectForKey:@"id"]);
}
}
[self callfbloginwebservice];
}];
[connection start];
}