Skip to content

Instantly share code, notes, and snippets.

@AbmSourav
Last active March 30, 2020 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbmSourav/5cf6b83b590f3a01b297e83bc4b40f4a to your computer and use it in GitHub Desktop.
Save AbmSourav/5cf6b83b590f3a01b297e83bc4b40f4a to your computer and use it in GitHub Desktop.
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