Take the 2-minute tour ×

When I access the list of my friends using the URL https://graph.facebook.com/me/friends?access_token=... I can see the list of my friends. I can do this programmatically as well.

Now, when I take the ID of any of my friends and replace it with "me" in the above URL, and paste the URL in the browser, I can see my friend's friends. I am unable to do this programmatically because it is giving me a HTTP 400 ERROR.

Does anyone know why this is possible by pasting the URL and not programmatically?

Thanks Abhishek S

share|improve this question
what is the exact error message in the response? –  ThdK Apr 18 '12 at 7:11
I cannot see the response but it is giving me a java.IO Exception. I am using the following code to read the URL: ByteArrayOutputStream baos = new ByteArrayOutputStream(); URLConnection con = url.openConnection(); con.setConnectTimeout(20000); con.setReadTimeout(20000); InputStream is = con.getInputStream(); int r; while ((r = is.read()) != -1) { baos.write(r); } return new String(baos.toByteArray()); –  Abhishek Shivkumar Apr 18 '12 at 7:13
Are you sure you are using the same id when you use the browser and when you try it programmatically? Can you show me some code you are using the make the request? –  ThdK Apr 18 '12 at 7:15
Yes, I am using the same ID. Here is the code: friendID2 = "503353623"; try { url = new URL("graph.facebook.com/"+friendID2+"/…; + accessToken); } catch (MalformedURLException e) { } try { result = ReadMyURL.readURL(url); } catch (IOException e) { } –  Abhishek Shivkumar Apr 18 '12 at 7:19
Is the user you're trying to get the friends for, that is USER_ID/friends, a user of your app? –  Nitzan Tomer Apr 18 '12 at 7:19
show 1 more comment

2 Answers

up vote 3 down vote accepted

You can not get the "friends of friends" using the facebook api.

For example, try the simple /me/friends with the Graph API Explorer, it should work fine. Then, take one of the ids there and try the same with FRIEND_ID/friends and you should get this:

  "error": {
    "message": "(#604) Can't lookup all friends of FRIEN_ID. Can only lookup for the logged in user or the logged in user's friends that are users of your app.", 
    "type": "OAuthException", 
    "code": 604

The error itself is very straight forward and explains exactly what the problem is. As for why that translates into a 400 error code for you is unclear.


You can't see the "friends of friends" in the browser as well, the reason that it works for you (probably) is that the user(s) you check the friends for (USER_ID/friends) installed the app that the access token belongs to, from the way you got to that url I assume that the app is the "Test_console".

How to check? Copy the access token from the url (USER_ID/friends?access_token=xxxxx), go to the Facebook Debugger and paste the token in the text field and click "Debug", it will show you info regarding the application.

The user you checked it for probably has that app "installed", if you check it for other users you will get that error when you get to a user who does not have that app "installed".

I hope this clarifies it for you.

share|improve this answer
Did you just copied this answer from stackoverflow.com/questions/3423671/… ? I don't think that's the case here, because it's working when he paste the url in the browser. –  ThdK Apr 18 '12 at 7:50
:) Nop. I wrote it myself, but I agree, the similarity is a bit frighting. Facebook treats requests differently when they are originating from apps or from browsers, and that's why there's a difference. When you try it with the API Explorer for example you'll get this error since it's an app, and you should get that error when you try it from any other app. –  Nitzan Tomer Apr 18 '12 at 7:55
But I am reading the same URL that I paste in the browser using simple JAVA code that reads the content from any URL using InputStream. So where does app come int picture here? Isn't it like just reading a URL programmatically? –  Abhishek Shivkumar Apr 18 '12 at 8:12
No, it's not the same thing. When you use a browser a name/id of the browser is being sent along side the request, it's called the "user agent string" which the server can use to decide how to respond to. When you use your java program to send the request, there's no user agent string, or one that differs from a browser one. But in any case, are you sure that you can get the list of friends of your friend in the browser? If so, are you sure that specific friend does not have the app installed? For me, I get the same error in the browser as well. –  Nitzan Tomer Apr 18 '12 at 8:25
yes, I can access Friends of Friends in the browser. Here is how you can check: Go to the following link: developers.facebook.com/docs/reference/api Click on "Friends:" link that you see. It opens your friends list in a new tab. Now take any of your friend's ID and paste it in the URL above, by replacing it with "ME". Hit enter and you will see your friend's friends again. Of course, now you cannot continue to the next stage here. Can you please check now? Thanks. –  Abhishek Shivkumar Apr 18 '12 at 8:43
show 3 more comments

I got friends of friends(limited) who are using application. I had same problem. Though it is very late for answering question, it will help somebody. That's why answering this question.

We can get friends of friends those are app users.

$fb_id= user id whose friends of friends required.

Try this fql query.


It needs following requirements:

  1. Your friend needs to be using application.
  2. Permission from application read_stream, publish_stream, publish_checkins.
share|improve this answer
add comment

Your Answer


