Getting facebook friends through plugin in phonegap
Posted By : Avilash Choudhary | 15-Dec-2014
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.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Avilash Choudhary
Avilash has excellent experience in developing mobile and web applications using jQuery , Javascript and PhoneGap. His hobbies are watching and playing cricket.