How to get user's username in v2.0 or later of Facebook's Graph API

后端 未结 3 394
醉梦人生
醉梦人生 2020-12-25 11:51

I used to get the user\'s username in the API 1.0 fairly easily, using /me and getting the username property of the response object.

Now I\'

3条回答
  •  有刺的猬
    2020-12-25 12:50

    I found a simple workaround that involves a get request to Facebook. Instead of the username, Facebook will give you an ID that is unique to your application.

    I have found that making a request to https://www.facebook.com/[profile_id] will then redirect to the user's real profile. The username can be extracted from the redirect URL.

    Example:

    > curl -i https://www.facebook.com/710290539
    HTTP/1.1 301 Moved Permanently
    Location: https://www.facebook.com/colinskow
    

    (Note: Since I am the owner of the app in test mode, this could possibly be an exception. Please let me know in comments if you are able to confirm this in a production environment.)

提交回复
热议问题