Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Guys,

Please help me.

I am doing a small application, which will ask the user to login with facebook and once logged in they asked for the permission to connected to my application. Then i will get the friends list of the user.

Its good till now.

Then i also want to know if the user in the FB friends list connected to my application ???? so i can show next to the image of my friendslist saying they connected or not connected.

How can i get the status. Please help me

Thank you guys.
Posted

Hi there,

So presumably you have some form of database of your users and what their Facebook profiles are? So in your database store also the user's Facebook ID. Then, when someone logs in, for each friend in their friend list, take the friend's Facebook ID and see if it is in your database. If it is, voila that friend is connected, if it isn't then that friend isn't connected to your site.

Data e.g.

User 1:
FacebookID: 0001
Username: John

User 2:
FacebookID: 0002
Username: Jane

When User 2 logs in, get her friend list from Facebook. Facebook returns something like:
Friends:
Friend1: FacebookID: 0001

Go through each friend in the list (in this example a list of one):
VB
FOR EACH AFriend in Friends
IF (From MyDatabase.Users WHERE FacebookID == AFriend.FacebookID SELECT Friends).COUNT > 0)
    Friend is connected
ELSE
    Friend is not connected
END FOR EACH


Hope this helps,
Ed
 
Share this answer
 
Comments
shekhardumala 17-May-12 9:11am    
Thank you for the response.

I have only the users that are friends on FB. I dont have any other people in my database. So how would i get that the person is connected to my application, i need to get this info from facebook.
Ed Nutting 17-May-12 9:15am    
Yes but when someone signs up, you have their account too. So you take the FacebookID from their account and store it in your database. Then when someone else signs up, you store their FacebookID and you can check their friend's list for FacebookIDs that are already in your database, from other people who have signed up. Think it through, the solution that I (and seemingly Birajdar) provide does work.

Ed
shekhardumala 17-May-12 9:20am    
Thank you ... again, But let me explane.
I am a new user , got to my website, and i logged into my website using FB, Now i see all of my friends as a list, but now i will see all the users , i dont know who already visited the website and already connected, so wants to find out if someone from my list already connected to the application.

thank you ...
Ed Nutting 17-May-12 9:27am    
But that's the point, YOU have a database of users and YOU store a copy of people's Facebook ID's when they sign up to your site. Then YOU can take the the new users friend list and check for friend's FacebookIDs in YOUR database. Thus, if someone has already connected to your site, their FacebookID will be in YOUR database and when you search for their ID (in YOUR database) from the new user's friend list then it will be there and you know they have connected. If YOUR database doesn't contain the FacebookID then that person has never connected to your site.

I hope this is clear now. You cannot do this entirely off the back of Facebook, YOU need to have YOUR OWN database.
Ed
Each facebook user has a unique id. Its a 12-16 digit unique numeric value. You need to store this value in your database for every user registered in your application.

So once you log in , fetch the friends list and check one by one if each of your friend is already registered in the application or not. If they are registered , then display his profile image using his facebook numeric id and the image URL.
 
Share this answer
 
Comments
shekhardumala 17-May-12 9:11am    
Thank you for the response.

I have only the users that are friends on FB. I dont have any other people in my database. So how would i get that the person is connected to my application, i need to get this info from facebook.
Ed Nutting 17-May-12 9:29am    
Awful design of the database! Massive no! Do not store a copy of every user's friends! Just store their individual FacebookID then check the new user's friend list (i.e. their friend's FacebookIDs) to see if they are in the database. If they are, they are connected, if not, they aren't connected. Your database design duplicates A lot of data unnecessarily...

Ed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900