Facebook Graph Api 2.1 get userid from username
Asked Answered
A

6

12

I am looking for a solution which can provide me user id from profile url or fb username

example :http://facebook.com/username

get userid of this url

and also when I try to read friends (I have friend related permission), I am getting blank data array ex:

 graph api requ: https://graph.facebook.com/v2.1/me/friends?access_token=xxxxx
 response:
    {
      "data": [
      ], 
      "summary": {
        "total_count": 455
      }
    }

Please let me know how can I get friend list and userid using username in Facebook graph api v2.1

Attar answered 26/9, 2014 at 14:30 Comment(3)
You can't. It is not possible to get user_id from username. And /me/friends return friends that are using the app and have granted it user_friends. So you don't have any friends that have done thatBig
Thanks for letting me know about fb not have api for getting user_id from username. but for /me/friends I have permission for (user_friends) but still I am getting blank data response, you can see above I am getting total_count of my friends but response of data is coming blank. and on more thing If you are testing this with old fb app then may be result will diff for you, I will suggest you just create a new fb app which will support only graph 2.1 it will give same type error for "me/friends" to you.Attar
You didn't read my response. You will only get friends that have granted your app user_friends permission.Big
A
7

graph.facebook.com/username has stopped working. There is an unpleasant workaround. In my limited testing, this works in Chrome.

Wherever you see the facebook user name in a timeline entry, right click and select "inspect element." In the window that opens, scroll up a little and look for the string:

"data-hovercard="/ajax/hovercard/hovercard.php?id=".

The Facebook id of the username you right clicked on follows the = sign.

This only seems to work on names on the timeline.

Arsenic answered 23/6, 2015 at 21:41 Comment(0)
T
3

Hi dhiraj you can get all of your friends username, user id and their profile picture by doing this....https://graph.facebook.com/v2.1/me/taggable_friends?access_token=xxxxx....Hope this helps...and please dont forget to upvote if you identify this as an answer

https://graph.facebook.com/v2.1/me/friends?access_token=xxxxx would return the friends who are using your app i.e., who have authenticated your app...where as https://graph.facebook.com/v2.1/me/taggable_friends?access_token=xxxxx will return all of your friends

Tabatha answered 30/9, 2014 at 7:41 Comment(6)
I am able to get taggable-friends, but when I call api graph.facebook.com/v2.1/me/friends?access_token=xxxxx , it just give me response { "data": [ ], "summary": { "total_count": 458 } }, I am not able to get friends name , just able to see total_count... , I have 'user_friends' permissionAttar
certainly it will give you response as data": [ ] since...call to api graph.facebook.com/v2.1/me/friends?access_token=xxxxx will return details of user friends data who have authorized your app i.e., who are using your app.....the response is returning null in the data means none of your friends is using your app...is it clear?Tabatha
by the way why you don't want to use me/taggable_friends to fetch the details of your friends ?Tabatha
I just want to get my friends list, I am using this api graph.facebook.com/v2.1/me/friends?access_token=xxxxx , It not work after I created a new app on facebook for production. It just return me{ "data": [ ], "summary": { "total_count": 458 } } it, but I am not able get friends name and idAttar
Check this link developers.facebook.com/docs/graph-api/reference/v2.1/user/….... where it is clearly mentioned that 1)This will only return any friends who have used (via Facebook Login) the app making the request. 2)If a friend of the person declines the user_friends permission, that friend will not show up in the friend list for this personTabatha
To make you understand... i will suggest you to do this, create a new facebook id of yours and then send friend request to the new facebook id from your old facebook id, then accept the friend request.....Then login to your application using your newly created facebook id then ...make a call to graph.facebook.com/v2.1/me/friends?access_token=xxxxx...now in the data": [ ] part you will get the details of the newly created facebook id...Please try this.....then you will get the conceptTabatha
P
3

You can send HTTP request to the facebook profile page from your server-side code
i.e. request to https://facebook.com/some_username
Parse the received response containing HTML source code and search for a <meta> tag that has a content attribute with a value looking like this fb://profile/xxx where xxx is going to be the profile ID you're looking for.

#Update (May, 2020):
Facebook has recently switched to a new web interface and the meta tag I mentioned above is found only in the older version.
In the new Facebook version you can find the profile ID in many places but All I found so far were inside the body of various <script> tags.
You may parse any script body that starts with requireLazy and look for

"result":{"data":{"user":{"id":"xxx"}

Or

"userID":"xxx"
Paronomasia answered 17/5, 2018 at 21:25 Comment(0)
H
1

I've found if you go to a username's page like:

https://www.facebook.com/username

If you right click on the user's photo, copy the image link you'll get something like :

https://www.facebook.com/photo.php?fbid=12332322&set=a.1afs2&type=3&source=11&referrer_profile_id=100024670088999

The referrer_profile_id is the user's facebook id. Not much help from an API perspective, but gets you the id.

Harkness answered 9/3, 2018 at 13:51 Comment(0)
S
0

I have also noticed that the JSON from the /me/home node gives user names and their ids from those people who liked anything. Since these people may also be friends, you might be able to partially figure out user ids for friends by looking at this feed in combination with taggable_friends. I am not sure what the Facebook (v2.3) terms of use says in this regard -- so maybe this isn't allowed?

Stereometry answered 8/7, 2015 at 17:35 Comment(0)
I
-3

Duplicate: api to get uid from profile URL on facebook

You can call the graph directly as such: https://graph.facebook.com/username where username is the username you want to lookup.

edit: out of date

Interaction answered 4/2, 2015 at 21:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.