using Facebook Rest API create Facebook Page Feed in WordPress websites.
This file contains 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 | |
$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