Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FirebaseAuth android get Facebook friends list

I use facebook login in my app. Once the users are logged-in I can get their basic facebook info such as display name, email, and phot url. I'd like to get their facebook friends list. I think I can get it "directly" with firebase but I don't remember how and I cannot find any info about it. I think I first have to tell Firebase to get friends list when people login with facebook, then I sould be able to get it with a method such as firebaseAuth.getCurrentUser().getFriendList().

Do you know how to get facebook friends list with firebaseAuth ?

Thank you,

Alex

like image 680
Alex9494 Avatar asked Mar 15 '17 18:03

Alex9494


2 Answers

It is feasible, but only the friends that also use your app. The trick is to add a scope to your login method. In Angular it looks like this

this.afAuth.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider().addScope('user_friends'))

That scope at the end is the trick. Then, you need at least two users that are friends on facebook to login. You will note the popup is different as it now asks permission for the user's friends.

The response will include an access token. Then you can use that token to request the user's friends that are also using the app with a GET request like this

https://graph.facebook.com/v2.11/{facebook_uid}/?fields=friends{name,id}&access_token={access_token}

Note I'm using a particular version, but you should change that to whatever you need.

like image 193
Noel Delgado Avatar answered Oct 26 '22 19:10

Noel Delgado


generally obtaining user's all friends list from Facebook is not possible, they removed this option years ago, with API v2.0 introduction... more info about and useful suggestions HERE

there is an official FB API called Graph API and HERE you have some doc about friend lists

and the Firebase... well, this is Google's product and it have nothing to do with Facebook... You are probably using FB mail address for creating an account in Firebase service/database, but it is keeping only this data plus some additional attributes if set (like photo or visible name).

firebaseAuth.getCurrentUser() returns FirebaseUser object, which have THESE methods - like you see: logpass, name, photo url and only few more methods. no option for getting friends list, because there is no method to set them, and no possibility to get this list from FB lib/API

like image 42
snachmsm Avatar answered Oct 26 '22 18:10

snachmsm