FirebaseAuth android get Facebook friends list
Asked Answered
K

2

7

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

Kosher answered 15/3, 2017 at 18:14 Comment(0)
T
3

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

Taste answered 15/3, 2017 at 18:52 Comment(1)
Ok, I just have added the user_friends facebook permission in my facebook login set up with firebaseAuth. Now when I try to log in I can read in the "facebook popup" : "this app will receive: your friends list". But I understand that I need the Graph API to be able to use it, I cannot get it with Firebase through the FirebaseObject for instance. Thank you for your help !Kosher
M
7

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.

Misdemeanant answered 27/11, 2017 at 22:55 Comment(0)
T
3

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

Taste answered 15/3, 2017 at 18:52 Comment(1)
Ok, I just have added the user_friends facebook permission in my facebook login set up with firebaseAuth. Now when I try to log in I can read in the "facebook popup" : "this app will receive: your friends list". But I understand that I need the Graph API to be able to use it, I cannot get it with Firebase through the FirebaseObject for instance. Thank you for your help !Kosher

© 2022 - 2024 — McMap. All rights reserved.