wordpress-facebook-twitter-feed

Facebook and Twitter Feeds for your site


Fetch RSS Feed from Facebook and Twitter
<!–?php–>
/*Paste the below function into your theme function file */
function getFacebookid_json($facebook_url){
$last_url_node = @explode(“/”,$facebook_url);
$last_url_node = $last_url_node[count($last_url_node)-1];
$url = “https://graph.facebook.com/&#8221;.$last_url_node;
$ch = curl_init($url);

facebook-twitter-feed

facebook-twitter-feed

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Host: graph.facebook.com’));
$data = curl_exec($ch);
$data = json_decode($data,true);
curl_close($ch);
return $data[‘id’];
}
function gettwitterid_json($twitter_url){
$last_url_node = @explode(“=”,$twitter_url);
$last_url_node = $last_url_node[count($last_url_node)-1];
$url = “https://api.twitter.com/1/users/show.json?screen_name=&#8221;.$last_url_node;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Host: api.twitter.com’));
$data = curl_exec($ch);
$data = json_decode($data,true);
curl_close($ch);
return $data[‘id’];
}
/*Paste the below code wherever you want to display your social feeds*/
$fbid = “facebook_uname”;
$twitid = “twitter_sname”;
$fb_rss_url = ‘https://graph.facebook.com/&#8217;.$fbid;
$twit_rss_url = ‘https://api.twitter.com/1/users/show.json?screen_name=&#8217;.$twitid;
$facebookident = getFacebookid_json($fb_rss_url);
$twitid = gettwitterid_json($twit_rss_url);
$fbrss = ‘http://www.facebook.com/feeds/page.php?format=rss20&id=&#8217;.$facebookident;
$twrss = ‘http://api.twitter.com/1/statuses/user_timeline.rss?user_id=&#8217;.$twitid;
include_once(ABSPATH.WPINC.’/rss.php’); // path to include script
$feed = fetch_rss($fbrss); // specify feed url
$items = array_slice($feed->items, 0, 1); // specify first and last item
if (!empty($items)) :
foreach ($items as $item) : $dat = $item[‘pubdate’]; ?>
<!–?php echo $cont = $item[‘description’]; ?>–>

Updated on <!–?php echo date(‘Y-m-d’, strtotime($dat)); ?>–>
<!–?php endforeach; ?>–>
<!–?php endif; ?>–>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s