简体   繁体   中英

Get Facebook friend list on Login using Ionic & Firebase Authentication

I want to save an array of user's Facebook friends using Ionic. I able to save the name and photo and am wondering how to get friend list. I would love to get the Friends User UIDs as well. I'm using Firebase Authentication.

facebookLogin(): Promise<any> {
return this.facebook.login(['email'])
  .then( (response) => {
    const facebookCredential = firebase.auth.FacebookAuthProvider
      .credential(response.authResponse.accessToken);

    this.afAuth.auth.signInWithCredential(facebookCredential)
    .then( userData => { this.userProfileRef.child(userData.uid).set({
    hypes: 23,
    name: userData.displayName,
    image: userData.photoURL,
    friends: userData.friends,
  }); this.userUID = userData.uid;
     })
    .catch((error) => { console.log("Firebase failure: " + JSON.stringify(error)); });

  })
  .catch((error) => { console.log(error) }); }}

You won't be able to get the friends list from Firebase. You will need to use the Facebook API. Since you already have the Facebook access token, you can just query the Facebook API for it. You can follow this guide for how to get that with the HTTP request: https://developers.facebook.com/docs/graph-api/reference/user/friends/ You will need to make sure you request the necessary scope for that "user_friends".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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