简体   繁体   English

FirebaseAuth android获取Facebook好友列表

[英]FirebaseAuth android get Facebook friends list

I use facebook login in my app. 我在我的应用程序中使用facebook登录。 Once the users are logged-in I can get their basic facebook info such as display name, email, and phot url. 一旦用户登录,我就可以获得他们的基本Facebook信息,例如显示名称,电子邮件和照片网址。 I'd like to get their facebook friends list. 我想得到他们的facebook好友列表。 I think I can get it "directly" with firebase but I don't remember how and I cannot find any info about it. 我想我可以“直接”使用firebase,但我不记得我怎么也找不到任何关于它的信息。 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(). 我想当人们使用facebook登录时,我首先要告诉Firebase获取好友列表,然后我可以使用firebaseAuth.getCurrentUser()。getFriendList()这样的方法来获取它。

Do you know how to get facebook friends list with firebaseAuth ? 你知道怎么用firebaseAuth获取facebook好友列表吗?

Thank you, 谢谢,

Alex 亚历克斯

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 通常从Facebook获取用户的所有朋友列表是不可能的,他们在几年前删除了这个选项,使用API​​ v2.0介绍...更多信息和有用的建议在这里

there is an official FB API called Graph API and HERE you have some doc about friend lists 有一个名为Graph API的官方FB API,在这里你有一些关于朋友列表的文档

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). Firebase ......好吧,这是谷歌的产品,它与Facebook无关......你可能正在使用FB邮件地址在Firebase服务/数据库中创建一个帐户,但它只保留这些数据加上一些额外的设置属性(如照片或可见名称)。

firebaseAuth.getCurrentUser() returns FirebaseUser object, which have THESE methods - like you see: logpass, name, photo url and only few more methods. firebaseAuth.getCurrentUser()返回FirebaseUser对象,它有这些方法 - 就像你看到的那样:logpass,name,photo url以及更多的方法。 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 没有获取好友列表的选项,因为没有设置它们的方法,也没有可能从FB lib / API获取此列表

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 在Angular中它看起来像这样

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. 然后,您需要至少两个Facebook上的朋友登录才能登录。 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 然后,您可以使用该令牌来请求同时使用该应用程序的用户的朋友使用这样的GET请求

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. 注意我使用的是特定版本,但您应该将其更改为您需要的任何版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM