How to know if user's facebook's friends are registred on your site? - facebook

I want to create a 'Find friends from facebook' button on my site. Many websites have it, and it basically gets your friends from facebook and identifies those of them who are already registred on that website, to allow you add them as friends or whatever.
I have clicked that button on a very famous website and the website show me a list with my friends who are registred on that website, and almost 1/3 of my friends where there.
I have been reading the facebooks API, have created an app, and finally managed to create a 'Find facebook friends' button. But when I click on that button, my website receives from facebook only an array with the name and fb ID of every friend I have.
How is that usefull for me? How can I know who of them are registred on my website to show it to the user that clicked the button? I thought it should give me for example the email of each friend, so I can compare it to my DB and get the registred users, but, now that I think of it again, it's true that it is impossible due to several fb privacy violations.
How do those websites know who of your friends are registred by clicking the button?
Thank you very much!

You need to associate a user's Facebook ID with their account on your site (in the user DB table for example).
Then you have the list of all Facebook IDs of your friends. You can run a query in your DB to see which of your registered users' Facebook IDs match the ones from your query.
Basically the intersection of 2 list of FB IDs.
The ones in both lists are your friends registered on the site.

If you're happy to add an extra permission to your FB authentication (publish_actions) then you you don't need to keep your own list of users in a DB to get this info - you can query the scores API for the app. Just make a Graph call to /APP_ID/scores and it will return a list of friends of the current user who are using this app. Your application doesn't even need to publish any scores info - in this scenario, the API will just return scores of 0.
The addition of publish_actions does mean that there will be an extra permission dialog appearing when users connect to your app/site if you are not already requesting this permission.
Only friends who have given your app/site the publish_actions permission will be shown in the list - so if you have an existing site and have not previously requested this permission then friends who are old users will not be shown. Totally understand this might not be suitable for you and perhaps you should implement Fabien Warniez's solution instead.
Javascript example:
FB.login(function(response) {
FB.api('/145634995501895/scores', function(scoresResponse) {
$.each(scoresResponse.data, function(key, value) {
console.log(value.user.id + ':' + value.user.name);
});
});
}, {scope: 'publish_actions'});
Replace 145634995501895 in the above code with your application ID.

Related

Accessing Friends List on new FB APIs for non-app users

I am building an app where users can send picture messages to friends and would like users to see their Facebook friends list when they login through FB. However, I am confused by Facebook's new API information regarding the access that an app can have to display someone's list of friends. On the FB change log information page it says:
1) Friend list is no longer part of the default permission set and has its own permission: Asking for access to a person's friend list is now a separate permission that your app must request. The new permission is called user_friends.
2) Friend list now only returns friends who also use your app: The list of friends returned via the /me/friends endpoint is now limited to the list of friends that have authorized your app.
https://developers.facebook.com/docs/apps/changelog
Does this mean that my app will only display to users their Friends that are also using my app? Is there no way for a User to see their entire friends list? And if not, how can I prompt the User to invite new friends to use my app?
Thanks.
Yes, that is exactly what it means, and for what you want to do there is no way to get the friends who did not authorize your App. But maybe you want to use the Send Dialog instead: https://developers.facebook.com/docs/sharing/reference/send-dialog
For that, you don't even need to authorize the user and he can choose the receiver on his own.

Getting the wrong Facebook Id in the AuthData Parse.com

I facing a problem when trying to get Facebook friends list.
When user login Parse restore on the user AuthData a wrong (temporary) Facebook id, and than when I'm trying to pull the friends list I can't get it since the Facebook id is not the "real" Facebook id.
I'm getting all right permissions from Facebook at login time and can login my app.
Any suggestions?
You are most likely getting an App Scoped ID, see App-scoped User IDs changelog: https://developers.facebook.com/docs/apps/changelog
It is not a temporary one, it will stay the same for every User in one App. It is just not the "real" one.
If you don´t get the friends (with /me/friends, i guess), it´s probably because you only get the friends who also use your App. This is also explained in the changelog:
App Friends: The /me/friends endpoint no longer includes the full list of a person's friends. Instead, it now returns the list of that
person's friends who are also using your app.

check if user likes a page without application perm request

I have a simple tab page, php sdk working and I know I can get the "like" for this specific page from the user signed_request.
This page is a colaboration with another company who also has an FB page. What i´d like to know is if I can get the like status of their page for the current user so I can authorize an action on this tab that is dependant of the user liking both my page and my partner´s.
Is this possible without using an actual app, an access_token and the appropriate perms requested?
e.g. my page is fb.com/Coke and my partner is fb.com/Target
On this specific tab page I want to enable a button only if me (Coke) is liked (which I can get already) and if my partner (Target) is also liked.
I tried the graphAPI (me/likes) and FQL (using the connection table) and both compalin of an unauthorized request.
Short Answer:
No, this will not be possible in a production setting.
Further explanation:
Some users have their list of likes as public. In that case, it would work.
But in order to get likes from a user that has that setting as anything but public (such as myself, only friends of friends can see it), then it requires an app and an access_token that has a user_likes permission.
From the documentation:
Permissions Required:
user_likes permissions if querying the current user.

Getting friend user id, and their photos

I am doing some research into the capacity of Facebook Connect. I have some questions on how a couple of bits of functionality.
Is it possible to fetch a list of all friends of a user?
The idea of this is that a user would log in using my site and then they could search through their friends and select one, and the site would get that friends users id and store it to the sites database.
Getting a photos from that user
After getting the friends user id, would it then be possible to get their photos? Or would the friend need to give the site permission to do that?
I am looking into a site where you can buy a greetings card for a friend, and i wanted to know whether my users would be able to login via facebook, pick a friend, get a photo and then at the time of their birthday it would send them a private message (which i think i know how to do) linking them back to my site where they could view the birthday card and their photo.
Thanks
To answer your questions:
Yes. Once you have an access token from the login process for a user, make a Graph API request to https://graph.facebook.com/me/friends. You can test this for yourself here: https://developers.facebook.com/tools/explorer?method=GET&path=me%2Ffriends
Yes. During the login process, you must request user_photos and friends_photos permissions after which you can use the access token for a Graph API request to https://graph.facebook.com/USERID/photos. This will only return those photos for a friend which the user is allowed to see for the current privacy settings.

Can you lookup friends of friends with the Facebook graph API?

My app needs to generate a list of friends for the logged in user, as well as the friends of the friends. The logged in user has authorized the app. So I have no trouble getting their friends. When I make the /friends/ call to the API using one of the friends' IDs, I get this error message:
Can't lookup all friends of [FB ID]. Can only lookup for the logged in user or the logged in user's friends that are users of your app.
I knew that the public visibility of one's friends is a configurable setting for each individual user, but if I understand this message correctly it means that you simply cannot do what I'm trying... ever.
Question #1: Is this true? Is there simply no way to lookup someone's friends' friends?
Question #2: If it's not possible, how do sites like Glassdoor.com manage this exact functionality?
You cannot get the friends of friends of the person who is using the app.
Glassdoor.com sends invitations to the user's friends and when someone accepts, they simply get his friends since he becomes a user of their app.