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

后端 未结 3 395
醉梦人生
醉梦人生 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:30

    As a workaround you can use the email as a unique identifier. Email address can be retrieved using "email" as the permission scope.

    Facebook has removed the username field from the new API version. It is not possible to retrieve the username. But Facebook provides an application specific unique ID. If you need to share the same user between several apps you can use the newly introduced Business Mapping API. This allows to add all the required apps to a group. In this case the ID will be unique among all the apps in the group.

    More information on Business Mapping API is available at https://developers.facebook.com/docs/apps/for-business 1

    0 讨论(0)
  • 2020-12-25 12:41

    I don't mean to be unhelpful, but it appears access to username has been removed from the API, as far as I can tell. Places where an app may have been using username, such as in the old share dialogs, can no longer do that when used with the 2.0 API. I think its also a way of preventing apps from having access to usable unique identifiers outside of the app scope - any user IDs you retrieve under 2.0 API are specific to your app alone.

    0 讨论(0)
  • 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.)

    0 讨论(0)
提交回复
热议问题