Created
February 6, 2013 21:14
-
-
Save magnificode/4725923 to your computer and use it in GitHub Desktop.
Facebook Feed via JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $FBid = 'FACEBOOK_ID_HERE'; | |
| //Get the contents of a Facebook page | |
| $FBpage = file_get_contents('https://graph.facebook.com/' . $FBid . '/feed?access_token=ACCESS_TOKEN&limit=4'); | |
| //Interpret data with JSON | |
| $FBdata = json_decode($FBpage); | |
| foreach ($FBdata->data as $news ) | |
| { | |
| //Explode News and Page ID's into 2 values | |
| $StatusID = explode("_", $news->id); | |
| echo '<div class="news-item">'; | |
| //Text/title/description/date | |
| echo '<p class="date"><strong>Posted '. timeSince(strtotime($news->created_time)) . '</strong></p>'; | |
| if (!empty($news->story)) { echo '<p>' . $news->story . '</p>'; } | |
| if (!empty($news->message)) { echo '<p>' . $news->message . '</p>'; } | |
| // if (!empty($news->description)) { echo '<p>' . $news->description . '</p>'; } | |
| if (!empty($news->link)) { echo '<a class="viewpost" target="_blank" href="' . $news->link . '">View related media</a>'; } | |
| echo '</div> <!-- end .news-item -->'; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment