-1

I want to get all of my facebook friends every day and I was searching which is the more efficient way to do it.

My first approach was to create a selenium webdriver script. It opens a web browser, visits /me/friends, scrolls down automatically until the list finishes and then it parses the names. It is working pretty good but it takes some time (approximately 4-5 minutes).

After some search on the graph API, it appears that it isn't possible to have your complete list.

Another approach is to request from facebook to download all of your data, but facebook sends you an email and you need to wait and download it etc. and still you have to wait.

Final approach was to use a chrome extension (the name is who deleted me) which it worked and it was faster than my approach. I am wondering how this extension worked and one thing that I noticed is that it didn't found a friend of mine which has passed away. I don't like a 3rd party extension to have my data and I prefer to do it on my own. So I am wondering is there an endpoint which returns your public friends? or what is the approach of this chrome extension to do that?

Is there any other programming way of fetching your friends? Sure you could use a headless browser and do some requests to the /me/friends and get the responses as it does a web browser when it scrolls down, but it is pretty difficult to understand which ajax calls are the correct ones.

Update: My approach of scrapping: https://gist.github.com/johndel/cd01a854e8bf36d9d30b44758607cf3d#file-check_friends-rb

It isn't the best code I can write, just a hack for seeing it done, just replace the sendkeys with your email / password and it will do the trick. My approach gets all of my friends (the chrome extension approach didn't found a friend of mine, that's why I think it is hitting another endpoint and it is doing it differently).

JohnDel
  • 2,092
  • 8
  • 35
  • 64

2 Answers2

1

/me/friends is a Graph API endpoint that will only get your a list of friends who authorized your App. It is not possible at all to get friends who did not authorize your App. Everything that WOULD be possible is not allowed on Facebook, because it involves scraping.

Scraping Terms: https://www.facebook.com/apps/site_scraping_tos_terms.php

More information: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • Yes I mentioned that and I know it doesn't work with graph API. Also I don't have a facebook app, just my browser... is this an automatic answer or what? – JohnDel Aug 05 '16 at 19:39
  • that is THE answer. it is not allowed and there is no endpoint for it. facebook has specific terms about scraping, i will add the link. – andyrandy Aug 05 '16 at 19:42
  • Ok fine, parsing isn't allowed but I am still curious what other ways this can be done (even if they aren't allowed by their policy... it's good to know how it can be achieved). – JohnDel Aug 05 '16 at 19:47
  • scraping the friends page is the only way, and that's not allowed. so, basically there is no way. feel free to add some code to your question if you want people to help you optimize, but imho we should not discuss stuff that is not allowed on stackoverflow. because...well, not allowed means "don't do it", and you should not give people ideas ;) (just my 2 cents though) – andyrandy Aug 05 '16 at 19:48
  • Well you can ask for permission to do it. Other than that I think the above chrome extension is doing it with some other way because it didn't find the exact list as I scrapped it. – JohnDel Aug 05 '16 at 19:50
  • then you scraped it wrong. impossible to say though, without your code. i am 99% sure that facebook will not give you permission though ;) - "is there a way to do xy" without adding what you have tried so far in detail is a bit too broad for stackoverflow anyway. just saying. – andyrandy Aug 05 '16 at 19:51
  • I added a gist with my code. My code found ALL of my friends, the chrome extension didn't, that's why I am saying that they should be doing it with some other approach. – JohnDel Aug 05 '16 at 19:59
  • well, then the chrome extension scraped it wrong. hard to say, without knowing the code of the chrome extension. – andyrandy Aug 05 '16 at 20:11
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/120329/discussion-between-johndel-and-luschn). – JohnDel Aug 06 '16 at 22:03
0

I found another url where I can fetch the users and it seems there are a bunch of them and more than one solution. So, a headless and faster approach is this gist:

https://gist.github.com/johndel/29afec4b159203baf7521cd5a50dbb60 and I guess it can be optimized even further with threads (maybe typhoeus and hydra).

JohnDel
  • 2,092
  • 8
  • 35
  • 64