Last active
March 30, 2020 15:13
-
-
Save AbmSourav/5cf6b83b590f3a01b297e83bc4b40f4a to your computer and use it in GitHub Desktop.
using Facebook Rest API create Facebook Page Feed in WordPress websites.
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 | |
$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