-3

I have two questions related in iOS vs Facebook API.

1) How to customise the facebook login view when user click the login btn to get user data.

2) In my application i want to use the facebook API. In this way i can able to retrieve the Users Data in this below method. But how can i save these users datas in my app locally.

Highly appreciated for your help !!!

[FBSession openActiveSessionWithReadPermissions:@[@"email",@"user_location",@"user_birthday",@"user_hometown"]
                                   allowLoginUI:YES
                              completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {

                                  switch (state) {
                                      case FBSessionStateOpen:
                                          [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error){


                                              if (error) {


                                                  NSLog(@"error:%@",error);


                                              }
                                              else
                                              {

                                                  // retrive user's details at here as shown below
                                                  NSLog(@"FB user first name:%@",user.first_name);
                                                  NSLog(@"FB user last name:%@",user.last_name);
                                                  NSLog(@"FB user birthday:%@",user.birthday);
                                                  NSLog(@"FB user location:%@",user.location);
                                                  NSLog(@"FB user username:%@",user.username);
                                                  NSLog(@"FB user gender:%@",[user objectForKey:@"gender"]);
                                                  NSLog(@"email id:%@",[user objectForKey:@"email"]);
                                                  NSLog(@"location:%@", [NSString stringWithFormat:@"Location: %@\n\n",
                                                                         user.location[@"name"]]);

self.fbUserDataDict = [NSDictionary dictionaryWithDictionary:user];

                                              }
                                          }];
                                          break;

                                      case FBSessionStateClosed:
                                      case FBSessionStateClosedLoginFailed:
                                          [FBSession.activeSession closeAndClearTokenInformation];
                                          break;

                                      default:

                                          break;
                                  }
                              } ];
  • Don't forget to ask for the user consent when saving his data. It'd be illegal otherwise http://webmasters.stackexchange.com/questions/24734/am-i-allowed-to-save-basic-user-data-from-facebook-in-my-own-web-apps-database#comment23335_24746 – jbouaziz Feb 08 '14 at 15:45
  • Hi pacman321, I mentioned only “basic account info” Like: name, email, gender, birthday, current city, and profile picture URL. – Shiv Suthan M user3287316 Feb 08 '14 at 17:14

1 Answers1

0

How about using something like Parse to store them locally ? You can also use SQLite. Though do you mind expanding a bit on what would you like to do ? Just store them locally ?

Random
  • 431
  • 8
  • 20
  • HI Random , I tried to store those values in a NSString Like name , email , gender but in that inside of methods i'm getting the switch case error can you please mentioned one sample i mean in that above block of codes can you write one step to store name to NSString... – Shiv Suthan M user3287316 Feb 08 '14 at 17:16
  • For that just i need a user to login my app easily with the support of their facebook email and name that's it. – Shiv Suthan M user3287316 Feb 08 '14 at 17:19
  • I don't quite understand, NSString is simply an object that holds immutable string, you said you want to store data locally, therefore you must have a local database, such as SQLite. – Random Feb 08 '14 at 17:36
  • HI random you are correct but for example i'm saying to store atleast nsstring. – Shiv Suthan M user3287316 Feb 08 '14 at 18:03
  • Hi random please visit again for my code because now i try to add the fb user dictionary to my dictionary but im getting error as follows : – Shiv Suthan M user3287316 Feb 08 '14 at 18:07
  • **Switch Case Is In Protected Scope** – Shiv Suthan M user3287316 Feb 08 '14 at 18:07
  • A simple Google search would've brought you this : http://stackoverflow.com/questions/7562199/when-converting-a-project-to-use-arc-what-does-switch-case-is-in-protected-scop – Random Feb 08 '14 at 18:40
  • Also, you must do some research yourself, I can't feed you with a spoon, use SQLite to store the data locally, use Google to find tutorials such as [this](http://www.raywenderlich.com/913/sqlite-tutorial-for-ios-making-our-app). – Random Feb 08 '14 at 18:41