Kumar V
Kumar V

Reputation: 8838

How to get user details using facebook connect

How can I get firstname and last name of facebook user while using f-connect?

I can login using api, but I couldn't get firstname and lastname of logged in user.

Upvotes: 2

Views: 289

Answers (2)

Matt McCormick
Matt McCormick

Reputation: 13200

$client = new FacebookRestClient(API_KEY, SECRET_KEY, SESSION_KEY);
$userinfo = $client->users_getInfo($client->users_getLoggedInUser(), array('first_name','last_name'));
echo $userinfo[0]['first_name'] . ' ' . $userinfo[0]['last_name'];

Upvotes: 4

Antoine Aubry
Antoine Aubry

Reputation: 12469

You have to invoke users.getInfo. In PHP, you would do it like this:

$userId = 1234567;
$fb = new Facebook(FACEBOOK_API_KEY, FACEBOOK_SECRET);
$fb->api_client->users_getInfo($userId, 'name, pic_square, first_name');

You can check the function's documentation here.

Upvotes: 4

Related Questions