Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access a user's Facebook friends list in Meteor?

I'm new to Meteor development, and I'm having a lot of trouble with this. I found the following guide, which is the closest thing I've found to a solution: http://www.andrehonsberg.com/article/facebook-graph-api-meteor-js

The .getFriends() function here looks promising as well, but I have no experience with this: https://github.com/maxkferg/meteor-facebook-collections/

I implemented the following code in client/config/config.js:

Accounts.ui.config({
    requestPermissions: {
        facebook: ['email', 'user_friends', 'user_location', 'user_events', 
        'friends_events', 'friends_location', 'friends_about_me',
        'user_status', 'friends_status', 'read_friendlists'],
    }
});

This properly generated the request for permissions upon log-in. (I do have an issue, though. I'm getting the following error: "Uncaught Error: Accounts.ui.config: Can't set requestPermissions more than once for facebook," which is odd, since it points to the hidden accounts_ui.js file, which I have no access to. Shouldn't I be able to override this just fine? The guide above has no mention of this error.)

I implemented the rest of the guide's code as well, but nothing seems to be working. Furthermore, the guide seems to implement a button on the screen that causes some aspect of the user's data to be displayed (friends, posts, etc.) in a list. I don't want any sort of display, though; I just want to be able to access the data (an array of Facebook-specific ids for the a given user's friends would be ideal) so that I can use it for various functions in my web app.

Any and all help would be really appreciated!

like image 320
Mason Hale Avatar asked Jan 20 '15 16:01

Mason Hale


1 Answers

From your comment I understand, that you only care about user_friends and email.

If you use the package accounts-facebook for Userlogin, you already have the email of the user. For using the login, you must configure the service. You do this serverside on startup (more info):

ServiceConfiguration.configurations.upsert({
        {service: "facebook"},
        { $set: {
          appId: "XXX",
          secret: "XXX",
          requestPermissions: ['user_friends'] //here you are requesting the permission to get the user's friends
        }
    });

The next step would be to get the user's friends. You could use a package to do it, or you could do it by hand: First you should check, if the user gave you permission. Send a Request to the Facebook-API (API):

GET /{user-id}/permissions

Hopefully you will get an object in the form:

{
  "data": [
    ...,
    {
      "permission": "user_friends",
      "status": "granted"
    }
  ]
}

This means, the user gave you permission to get his friends (more info).

In the next step, you query the Graph-API for the friendlists more info:

GET /v2.3/{user-id}/friendlists HTTP/1.1
Host: graph.facebook.com

This will get you all the friendlists of the user. In the last step you can query for all or some of the lists (e.g. 'Close Friends', 'Acquaintances') with more info:

GET /v2.3/{friendlist-id} HTTP/1.1
Host: graph.facebook.com
like image 175
Daniel Budick Avatar answered Oct 06 '22 13:10

Daniel Budick