简体   繁体   English

Facebook Graph Api 2.1 从用户名中获取用户 ID

[英]Facebook Graph Api 2.1 get userid from username

I am looking for a solution which can provide me user id from profile url or fb username我正在寻找一种解决方案,它可以从个人资料 url 或 fb 用户名中为我提供用户 ID

example :http://facebook.com/username

get userid of this url获取此 url 的用户 ID

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请让我知道如何使用 Facebook graph api v2.1 中的用户名获取好友列表和用户 ID

graph.facebook.com/username has stopped working. graph.facebook.com/username 已停止工作。 There is an unpleasant workaround.有一个令人不快的解决方法。 In my limited testing, this works in Chrome.在我有限的测试中,这适用于 Chrome。

Wherever you see the facebook user name in a timeline entry, right click and select "inspect element."无论您在时间线条目中看到 facebook 用户名的任何位置,右键单击并选择“检查元素”。 In the window that opens, scroll up a little and look for the string:在打开的窗口中,向上滚动一点并查找字符串:

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

The Facebook id of the username you right clicked on follows the = sign.您右键单击的用户名的 Facebook id 跟在 = 符号之后。

This only seems to work on names on the timeline.这似乎只适用于时间轴上的名称。

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嗨 dhiraj,您可以通过执行此操作获取所有朋友的用户名、用户 ID 和他们的个人资料图片.... https://graph.facebook.com/v2.1/me/taggable_friends?access_token=xxxxx ....Hope这有帮助......如果你认为这是一个答案,请不要忘记投票

https://graph.facebook.com/v2.1/me/friends?access_token=xxxxx would return the friends who are using your app ie, 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 https://graph.facebook.com/v2.1/me/friends?access_token=xxxxx将返回使用您的应用程序的朋友, 即已对您的应用程序进行身份验证的朋友......如https://graph.facebook。 com/v2.1/me/taggable_friends?access_token=xxxxx将返回你所有的朋友

You can send HTTP request to the facebook profile page from your server-side code您可以从服务器端代码向 Facebook 个人资料页面发送 HTTP 请求
ie request to https://facebook.com/some_username即请求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.解析接收到的包含 HTML 源代码的响应并搜索具有content属性的<meta>标记,该标记的值类似于fb://profile/xxx ,其中xxx将是您要查找的配置文件 ID。

#Update (May, 2020): #更新(2020 年 5 月):
Facebook has recently switched to a new web interface and the meta tag I mentioned above is found only in the older version. Facebook 最近切换到了一个新的网络界面,我上面提到的元标记只能在旧版本中找到。
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.在新的 Facebook 版本中,您可以在许多地方找到个人资料 ID,但到目前为止我所找到的都是在各种<script>标签的正文中。
You may parse any script body that starts with requireLazy and look for您可以解析任何以requireLazy开头的脚本主体并查找

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

Or或者

"userID":"xxx"

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. referrer_profile_id是用户的 Facebook id。 Not much help from an API perspective, but gets you the id.从 API 的角度来看没有多少帮助,但可以为您提供 id。

I have also noticed that the JSON from the /me/home node gives user names and their ids from those people who liked anything.我还注意到来自 /me/home 节点的 JSON 提供了那些喜欢任何东西的人的用户名和他们的 ID 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.由于这些人也可能是朋友,因此您可以通过结合 taggable_friends 查看此提要来部分找出朋友的用户 ID。 I am not sure what the Facebook (v2.3) terms of use says in this regard -- so maybe this isn't allowed?我不确定 Facebook (v2.3) 使用条款在这方面是怎么说的——所以也许这是不允许的?

Duplicate: api to get uid from profile URL on facebook重复: api 从 facebook 上的个人资料 URL 获取 uid

You can call the graph directly as such: https://graph.facebook.com/username where username is the username you want to lookup.您可以直接调用图表: https : //graph.facebook.com/username其中 username 是您要查找的用户名。

edit: out of date编辑:过时了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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