DaSilva
DaSilva

Reputation: 1358

Get email and profile´s image with iOS Facebook-SDK 3.1

Recently I started my adventure of my apps integration with facebook-sdk.

I have an application that provides login with Facebook. Thus the idea, after creating a session with facebook, is to get some data from the user and create a new one on my server with some data,

Thus, I am using the latest version, facebook sdk-3.1. I created a session with the permissions of the user to get the email.

    NSArray *permissions = [[NSArray alloc] initWithObjects:
                        @"user_location",
                        @"email",
                        nil];

[FBSession openActiveSessionWithReadPermissions:permissions
                                   allowLoginUI:YES
                              completionHandler:
 ^(FBSession *session,
   FBSessionState state, NSError *error) {
     [self sessionStateChanged:session state:state error:error];
 }];

The session is successfully created, after that I start creating user.

 if (FBSession.activeSession.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:
         ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
             if (!error) {

                 self.userData.firstNameUser=user.name;
                 self.userData.lastNameUser=user.last_name;
                 self.userData.mainLocation=user.location.name;
                 self.userData.urlImageUser=user.link;
             }
         }];   
    }

So, how can i get the other data, email and image´s Profile, of the user using the last SDK, to sent to my server?

Thanks

Upvotes: 1

Views: 4512

Answers (2)

Enrico Cupellini
Enrico Cupellini

Reputation: 445

It works. Just add

[self.view addSubview:profileImage];

Upvotes: 0

Navdeep Singh
Navdeep Singh

Reputation: 116

you have user's profile image in user object itself.

Just create the object of FBProfilePictureView set the object's ProfileID property.

e.g.

FBProfilePictureView *profileImage = [[FBProfilePictureView alloc] initWithFrame:frame];
profileImage.profileID = user.id;

It will show user's profile image .

You can add the following code in your handler response .

Upvotes: 10

Related Questions