And for that purpose I had to fetch the list of videos published by a particular YouTube user which can only be fetched in the form of JSON, RSS or Atom Feed. I decided to go with JSON, initially it was difficult for me to fetch the appropriate values I needed because the JSON returned by YouTube is quite complex in structured but finally I was able to sort it out.
JSON stands for JavaScript Object Notation and is mainly used to transmit such structured data over a network connection.
Example:
{
"firstName": "Atul",
"lastName": "Narang"
}
In my case the JSON has to be parsed from the following URL -http://gdata.youtube.com/feeds/api/videos?max-results=5&alt=json&orderby=published&author=designworxz
If you change the last parameter in the URL which is "author=designworxz" to "author=your youtube username" it will fetch list of videos published by you in the form of JSON.
The great community over at http://json.org have created a JSON parsing library for AS1, AS2 & AS3. But we will focus on Flash CS3 & AS2.0. You can find that parse class here: http://json.org/JSON.as
Below is the code to parse the JSON returned by YouTube -
import JSON;
var jsondata:LoadVars = new LoadVars();
jsondata.onLoad = function(success) {
if (success) {
trace("load successful");
var o:Object = json.parse(
unescape(this.toString())
);
var s:String = json.stringify(o);
trace(s);
} else {
trace("unable to load JSON data");
}
};
jsondata.load("http://gdata.youtube.com/feeds/api/videos?max-results=5&alt=json&orderby=published&author=designworxz");
The variable "s" will display the complete JSON returned by YouTube in the Output window & then the only thing you have to do is to fetch the required String, Variables & Values from the returned JSON.
Good Luck!!