Search code examples
phpfacebook-graph-apifacebook-php-sdk

How do I find out what user posted to my wall via the Facebook PHP SDK?


I'm trying to find out the user ID or name for a user that left a post on my Facebook feed.

I'm developing a script to work out some stats about the "tie strength" or connectivity of me to my friends on Facebook. Part of this is doing counts on stats such as how many times a particular friend has posted on my wall. I can use the /me/feed and /me/posts end-points to figure out feed entries that I've posted and feed entries that other have posted on my wall. the only problem is, the wall posts from others doesn't have any identifying attributes so I can't figure out who made the post. Does anyone know if this is even possible via the Facebook API anymore?


Solution

  • When you call the /me/feed, you get an array of posts with their id.

    Then you can use the /post/post-id endpoint to retrieve the information of the user.

    For example, if your post-id is 1687441367965569, then you can call the following endpoint:

    /1687441367965569?fields=from
    

    And this would return a JSON like the following:

    {
      "from": {
        "name": "First Name Last Name",
        "id": "1231231234123123"
      },
      "id": "1687441367965569"
    }
    

    For more information: https://developers.facebook.com/docs/graph-api/reference/v2.11/post