Monday, June 2, 2008

Fetch Data From Yahoo Pipes using JavaScript

How to fetch data from Yahoo Pipes using javascript:
First of all create function named getFeed which contains the parameter as feed as shown below:

function getFeed(feed) {
var newScript = document.createElement('script');
var pipeId=15154 //your pipe id newScript.type = 'text/javascript';
newScript.src = 'http://pipes.yahoo.com/pipes/pipe.run?_id='+ pipeId +'&_callback=piper&_render=json&searchInput='+feed;
document.getElementsByTagName("head")[0].appendChild(newScript);
}

In above function at newScript.src = 'http://pipes.yahoo.com/pipes/pipe.run?_id='+ pipeId +'&_callback=piper&_render=json&searchInput='+feed; linethere is something like _callback=piper which calls a function named piper which is used to fetch data. And result will be in JSON format.

The piper function is like this:

function piper(feed) {
var i;
var flk=feed.value.items[0].flickr;
var ytb=feed.value.items[1].ytb;
for (i=1; i<=parseInt(flk); i++) {
var link=feed.value.items[i].link;
var isrc=feed.value.items[i].description;
}
}
Here in above function we have tried to get date from flicker.com and youtube.com.The variable flk fetches data from flicker and ytb fetches data from youtube using yahoo pipes.If you have more then one outputs from yahoopipes then do as shown above.
Now as shown above in the for loop you can get data for particular results by using feed.valoe.items[i] and its propertiessuch as link, description etc.

1 comment:

Priyank Agrawal said...

gud one...
continue work like this...