首页 文章

在Facebook Graph API 2.0中获取用户名字段

提问于
浏览
56

"old" Facebook Graph API有一个"username"字段,可用于创建人类可读的配置文件URL . 我的用户名例如是"sebastian.trug",这会产生Facebook Profiles 网址http://www.facebook.com/sebastian.trug .

使用来自"/me"检索的用户数据的Graph API 2.0 Facebook has removed the "username" field .

有没有办法通过2.0 API获取此数据,或者“用户名”现在被视为已弃用的字段?

8 回答

  • -3

    Facebook摆脱了用户名,因为用户名是通过Facebook发送电子邮件的一种方式 .

    例如,给定网址 http://www.facebook.com/sebastian.trug

    相应的Facebook电子邮件将是 sebastian.trug@facebook.com

    如果通过电子邮件发送,将直接收到 messages (如果 message 设置设置为 public ),否则收到 other 收件箱 .

  • 6

    User对象的 username 字段已被删除,并且在Graph API v2.0中不存在 . 在API的v2.0中,无法获取用户的FB用户名 .

    资料来源:https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api

    “/ me / username不再可用 . ”

  • 19

    @Simon Cross - 它被弃用了,是的 . 这不是问题,问题是如何获得它 - 并且 - 更进一步 - 我想知道为什么Facebook做出了如此可怕的选择并删除了用户名 . 数百个依赖用户名在其服务上创建帐户的应用程序将被破坏 .

    @ user3596238 - 您可以坚持使用V.1 API,它将持续到2015年4月底,到目前为止还不是最好的解决方案,但到目前为止Facebook可能无关紧要 . https://developers.facebook.com/docs/apps/changelog

    解决方案:除了实际的Facebook登录信息外,还要求用户输入用户名? - 在我看来,无论如何,这使得Facebook登录毫无意义 .

  • -5

    虽然2.0 SDK不再提供 username 字段,但如果您拥有用户ID号(无论如何您可能会用它来访问图表),它很容易被删除 .

    网址 facebook.com/<user id> 将重定向到 facebook.com/<username> ,然后可以随意提取 .

  • 33

    我的方法是通过用户配置文件使用nokogiri来删除用户名 . 有点像(红宝石):

    html = RestClient.get("http://facebook.com/123123xxx)
    doc = Nokogiri::HTML(html)
    username = doc.css('head meta')[1].attributes["content"].value
    
  • 2

    其中一种方法是使用cURL访问facebook.com/,然后按照重定向进行操作 .

    该页面重新显示到facebook.com/

  • 5

    灵感来自@RifkiFauzi的answer,这是我在纯Python中的解决方案

    #get html of a page via pure python ref. https://stackoverflow.com/a/23565355/248616
    import requests
    r = requests.get('http://fb.com/%s' % FB_USER_ID) #open profile page of the facebook user
    r.raise_for_status()
    html = r.content
    
    #search string with regex ref. https://stackoverflow.com/a/4667014/248616
    import re
    # m = re.search('meta http-equiv="refresh" content="0; URL=/([^?]+)\?', html)
    m = re.search('a class="profileLink" href="([^"]+)"', html)
    href = m.group(1) #will be https://www.facebook.com/$FB_USER_NAME on 201705.24
    username = href.split('/')[-1]
    print(href)
    print(username)
    
  • 23
    https://graph.facebook.com/?id=100005908663675
    

    只需将id更改为任何内容 .

相关问题