Showing posts with label rss. Show all posts
Showing posts with label rss. Show all posts

Tuesday, June 3, 2014

How to fetch Rss Feed Using Google api


Displaying RSS feeds easily using Google Ajax Feed API

Displaying RSS feeds from other sites (ie: CNN or Digg) on your own is a nice way to show constantly updated content automatically. However, for the novice web developer, setting this up can be daunting, requiring both knowledge from you and your server's ability to host remote files. Google's Ajax Feed API changes all that, by basically enabling any webmaster to display RSS feeds on their sites using some JavaScript code. It hosts the desired RSS feeds on their servers for you, caches them, and returns the data in either JSON or XML format for you to utilize. All that's left is for you to use some JavaScript to parse this data and output it on your page.
In this tutorial, I'll show you how to harness Google Ajax Feed API to fetch a RSS feed and display it on your site. Here are a few examples:
                                                                                   
/*








<script>
google.load("feeds""1");

// Our callback function, for when a feed is loaded.
function feedLoaded(result{
  if (!result.error{
    // Grab the container we will put the results into
    var container document.getElementById("content");
    container.innerHTML '';

    // Loop through the feeds, putting the titles onto the page.
    // Check out the result object for a list of properties returned in each entry.
    // http://code.google.com/apis/ajaxfeeds/documentation/reference.html#JSON
    for (var 0result.feed.entries.lengthi++{
      var entry result.feed.entries[i];
      var div document.createElement("div");
      div.appendChild(document.createTextNode(entry.title));
      container.appendChild(div);
    }
  }
}

function OnLoad({
  // Create a feed instance that will grab Digg's feed.
  var feed new google.feeds.Feed("http://www.digg.com/rss/index.xml");

  // Calling load sends the request off.  It requires a callback function.
  feed.load(feedLoaded);
}

google.setOnLoadCallback(OnLoad);
</script>

Wednesday, April 9, 2014

How to Fetch Data from RSS Using PHP


<style>
#data{
width:400px;

}
#data h2{
width:100%;
color:#1266ae;
padding:5px;
}
#data p{
border:1px solid #c6c6c6;
padding:5px;
}
#data p img{
width:100%;
}
</style>
<?php
// create a new DOMDocument object
$dom = new DOMDocument();
  //load a remote xml file
  $result = $dom->load("http://blog.lettersandlight.org/rss");
  //did the load work?
  if ($result) {
    //get an array of the items in the rss
    $items = $dom->getElementsByTagName('item');
    //loop through the array
    foreach($items as $item){
      //get the title of the current item
      $title = $item->getElementsByTagName('title')->item(0)->nodeValue;
      //get the description of the current item
      $desc = $item->getElementsByTagName('description')->item(0)->nodeValue;
      //output some of the collected data
 echo("<div id='data'>");
      echo "<h2> $title</h2><br>";
      echo "<p>$desc</p>";
 echo("</div>");
    }
  } else {
    echo "there was a problem reading the rss feed, bummer\n";
  }
?>