Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using Facebook Rest API create Facebook Page Feed in WordPress websites.
<?php
$facebook_feed = get_transient( '_facebook_cash' );
$url_queries = 'fields=status_type,created_time,from,message,story,full_picture,permalink_url,attachments.limit(1){type,media_type,title,description,unshimmed_url},comments.summary(total_count),reactions.summary(total_count)';
$page_id = 'your facebook page id';
$token = 'your access token';
$url = 'https://graph.facebook.com/v4.0/' . $page_id . '/posts?' . $url_queries . '&access_token=' . $token;
if ( false === $facebook_feed ) {
$fb_posts = wp_remote_get( $url );
$facebook_feed = wp_remote_retrieve_body( $fb_posts );
set_transient( '_facebook_cash', $facebook_feed, 5 * MINUTE_IN_SECONDS );
}
print_r( json_decode( $facebook_feed ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.