Mike J Aspinall
Mike J Aspinall

Reputation: 109

get user email from Facebook Using FBgraphUser In Parse

Im Trying to store the users email address in mt parse database but i cant seem to find the right way of getting this done my code below

FBRequest *request = [FBRequest requestForMe];
    [request startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *result, NSError *error) {


        if (error) {
            // Handle it
        } else {
            PFUser *me = [PFUser currentUser];
            me[@"facebookId"] = result.objectID;
            me[@"facebookName"] = result.name;
            me[@"facebookProfile"] = result.link;

            [me saveEventually];
        }
    }];
}

Thanks in advance

Upvotes: 0

Views: 716

Answers (1)

kelin
kelin

Reputation: 11985

Actually, result is an NSDictionary instance, conforming to FBGraphUser protocol. That mean it still can be treated as dictionary, for example you can send -objectForKey: message to it. Actually FBGraphUser protocol only adds a "shortcuts" for some objects, stored in the dictionary. So, by calling:

NSString *mail = result[@"email"];

You will get the email. This is a handy equivalent for:

NSString *mail = [result objectForKey:@"email"];

For all possible keys for user look Graph Api Reference.

Upvotes: 1

Related Questions