Thursday, 9 August 2018

Get Facebook Post Information With PHP

In a previous tutorial, I showed you how to get a list of posts from a Facebook page using PHP. In this tutorial, I will show you how to get detailed information about a specific Facebook post. We will do this using PHP and Facebook’s Graph API.
For this API call, we do not need to use an access token:
An explanation of the code above:
  • We set the unique ID of the post in question. The ID is basically the Facebook Page ID and the post ID, concatenated together with an underscore character.
  • We retrieve the URL in question using PHP’s file_get_contents function.
  • We decode the returned JSON into an associative array using the json_decode function.
  • Finally, we dump it out onto the page so that we can see the structure and what kind of information is available.
The type of information that is returned with this call:
  • link: The URL that was included in the post. This is typically a link to a website.
  • shares: The number of shares that the Facebook post has.
  • created_time: A timestamp showing when the Facebook post in question was made public.
  • message: This is usually the textual blurb or description that the page admin added when making the post.
  • status_type: The status type. Example: “shared_story”
  • likes: A paged list of likes. Note how I used the word paged there. This API call will not show you all of the likes (it was only showing the first 25 likes when I wrote this guide).
  • comments: A paged list of comments (see above).
  • name: When a link to an article is shared, the name element contains the title of the page (usually taken from the meta title of the shared page).
  • description: When a link is shared, this element will contain the small textual description that you see below the title (usually taken from the meta description or the first few sentences of the article).
  • type: The post type. Example: “link”
There is a lot of information returned in this call, so be sure to run the code above and take a look for yourself.

0 comments:

Post a Comment