Yahoo! Live API Usage Example
This sample will cover creating a collection of four random broadcasts using our Javascript and REST APIs. It should be used for a guide only, the code presented in this sample is not guaranteed to be production ready.
If you are impatient and want a sneak peak of the finished sample, see it here: Yahoo! Live Randomizer.
REST
Using the REST API, we will grab a collection of random streams that we can display on our page.
Javascript and Flash Embedding
Once we embed our Flash file into the page, we can interact with it via the Javascript API which is documented here.
Creating the sample
Add your fallback content to the page
Looking at the source of our sample page, you will see four HTML elements which have fallback, or alternative content. This is content that will be replaced by our Flash files. You can assume that users who see the alternative content do not have Flash and/or Javascript installed. For example:
<div id="spot1">Alt content 1</div> <div id="spot2">Alt content 2</div> <div id="spot3">Alt content 3</div> <div id="spot4">Alt content 4</div>
In a real-world scenario you would want to provide relevant content to your users such as static images, or links to download the latest Flash player and instructions on enabling Javascript
Query REST API
We use PHP and curl to gather data about broadcasts using the Yahoo! Live REST API. We are using the following querystring parameters:
sortSet to random, the broadcasts returned from the server will be randomly sorted.formatSet to json, since we are going to store the result of this query as a Javascript variable.countSet to 50, which means to return a max of 50 results. If there are less than 50 active broadcasts, the actual count will be less than 50.
For more information on REST and PHP, click here.
Embed Flash content
As discussed here, we prefer SWFObject 2 to embed our Flash into our pages. It provides an easy way to perform version checking for the Flash Player, as well as offer the alternative content fallback we created above.
The Flash movie we want to embed can be found at http://live.yahoo.com/swf/v1/ylsp/<permalink>, where <permalink> refers to a user's Channel ID. This is the information we will be using from the REST result which we now have in a Javascript variable called result.
Note that you will need to provide the correct path to expressInstall.swf located on your server. Also, Flash 9.0.47 is our minimum required version of Flash for use with Yahoo! Live. If you are using an alternative embedding method, make sure you can enforce a minimum version of 9.0.47.
Using setPermalink()
The following is a Javascript function that will randomize the broadcasts by calling setPermalink() on the embedded Flash movie. We also incorporate the use of Yahoo User Interface components to allow easier interaction with the Dom as well as Event handling. You can read more about YUI here.
Conclusion
This example demonstrates how to use the Javascript and REST APIs to create custom Yahoo! Live applications. Refer to the Yahoo! Live API documentation for the entire list of functions and their descriptions.
Ready to get started?
By applying for an Application ID for this service, you hereby agree to the Terms of Use


Send Your Suggestions