Here it is another tutorial on Facebook app development and in this article I am going to share you that how you can get friends list of any user using Facebook API (Application Programming Interface) so hope you will like it because you can use it in different ways like you can get friends list of any user who will use your app even if the user has made friends list visible only to him it’s like exposing friends on Facebook. You can use this method in many different ways but I am not going to describe all of them because you already know the importance of this article if you are beginner Facebook app developer.
Facebook API: Get Friends List
If you do not know a bit about Facebook app developing then read develop FB app using PHP SDK to learn basics of Facebook application development. So, now let me show you the code then I’ll explain it to you. Read another article to integrate Facebook with WordPress blog.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
- You already know the basic structure if know then read my another article the URL is shared above.
- On line number 68 I have used a line to collect data about user’s friends.
- On line number 82 I wrote a line which will get total number of friends and will assign that to $total_friends variable so that we can use while loop to get all friends’ names not more or less.
- Actually the $user_friends['data']['name'] will show the name of first friend that’s why we got total number of friends so that we shall use it to echo all friends’ names by incrementing the $start variable as you can see on line number 88 so it will work like this, first the $start is 0 as described on line no. 84 then first it will show name of first friend then it will increment the $start variable by 1 so the value of $start variable will be 1 then it will show the second friend’s name and so one until the last friend.
- When the $start variable will be bigger than $total_friends then it will stop while loop see line number 85 so it will work nicely and smoothly without any trouble.
- You can also get IDs of Facebook users’ friends just by replacing ['name'] with ['id'] on line no. 86.
Now you can use the friends list to any file using PHP so that you can see any user’s friends’ names at any time, you can also make this code working without showing or echoing anything so that the logged in user will not see anything but behind it will steal his/her friends’ names. if you like this tutorial then read my another article to develop a Facebook app like love calculator. If you need any help regarding this tutorial then simply comment below I will reply you as soon as possible, thanks for reading my article please share it on social networks.