Display public facebook posts on your website
A straightforward way to get your facebook public posts onto another website without requiring your guests to have a facebook account.
- Log into the facebook account you want to display the posts of
- Go to https://developers.facebook.com/apps, it will ask you for your password again
- On the top right of the next screen, click on the button "+Create New App"
- In the first field on the form enter an "App Name" and click "Continue". You do not need to enter anything for the other 2 fields. You may then be asked to enter the captcha validation text.
- On the next screen you will see values for “App ID:” and “APP Secret:”, you will use these in your code when you make a request.
- Click “Save Changes”
- To make the request and get facebook posts add the following lines to your PHP code:
//Request to facebook to obtain an access token. Replace the Xs so client_id's Xs is the value from “App ID” and client_secret's Xs is “App Secret”
$access_str = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=XXXXXX&client_secret=XXXXXX&grant_type=client_credentials');
//Request the public posts. Replace "YOUR-PROFILE-NAME" with your profile name.
$json_str = file_get_contents('https://graph.facebook.com/YOUR-PROFILE-NAME/feed?access_token='.$access_token);
//decode json string into array
$data = json_decode($json_str);
//Now iterate through $data to get the information you want to display.