naveen
naveen

Reputation: 1068

how do i get the facebook friends username in php?

I want to get the only fb username how it is? This is my code

$user = $this->facebook->user();
$fbfriends = $this->facebook->call('get', 'me/friends');
$friends=$fbfriends->data;

here it returns the name and id.But the name is not username.is there any solution to get the username only from the above function using?

Upvotes: 0

Views: 1946

Answers (3)

Suman Ansari
Suman Ansari

Reputation: 195

For getting your username

http://graph.facebook.com/id?fields=username

and for friends usernames

http://graph.facebook.com/id/friends?fields=username&access_token=XXXXXXXXXXXXXXXXXXXX

For more information Facebook Graph Api Fields Expansion

Upvotes: 0

user7282
user7282

Reputation: 5196

try this

 https://graph.facebook.com/id 

you will get a json result, including name

Upvotes: 0

Viren Rajput
Viren Rajput

Reputation: 5736

Try this:

$user = $this->facebook->user();
$fbfriends = $this->facebook->call('get', 'me/friends?fields=id,username,name');
$friends=$fbfriends->data;

This will fetch the username, id and the name of the user.

Upvotes: 2

Related Questions