Getting facebook friends through plugin in phonegap

Posted By : Avilash Choudhary | 15-Dec-2014


Facebook Friends via Plugin in Phonegap
If you are building a phonegap application and you are using phonegap facebook plugin to login through facebook. So you may have some features that require your facebook friends list.

First of all you need to setup the Facebook Plugin for your app to login through facebook. For installation of facebook plugin you can refer to the blog.

http://www.oodlestechnologies.com/blogs/Facebook-Integration-with-IOS-in-Phonegap

Below is the code that let you login through facebook and return logged user friends.

 FB.login(function(response) {
			if (response.status == "connected") {
				FB.api("/me/friends", function(response) {
					if (response && !response.error) {
						/* handle the result */



					}							
				}
		 	  }
		}, {
			scope : "email,user_friends"
		});

FB.login function is to login through facebook which has callback function. From that you can get access token, which will be required to get further information of logged user. such as his name,id etc.

 

FB.api  is a facebook Graph Api function which returns the friend list of current logged user.

But it has some drawbacks. It return only those friends who have already allowed access to that plugin used in your app for facebook login.

 

To get the friends profile picture you need to hit the below api which will return the image.

http://graph.facebook.com/{id}/picture?type=large

In the above link you need to pass the friends user id in place of  {id}. That you have received from FB.api method.

 

About Author

Author Image
Avilash Choudhary

Avilash has excellent experience in developing mobile and web applications using jQuery , Javascript and PhoneGap. His hobbies are watching and playing cricket.

Request for Proposal

Name is required

Comment is required

Sending message..