Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Youtube data not displaying

I'm pulling JSON data from youtube and I am having the hardest time getting the data to populate a table view. I am displaying the raw data in the debug window with success and I am pulling keys with no issues. When I launch the iPhone Simulator, it just shows a blank white screen. I am not sure what I am missing. Any suggestions?

var winYoutube = Titanium.UI.currentWindow;

function loadYoutube()
{
    // Empty array "rowData" for our tableview
    var rowData = [];
    // Create our HTTP Client and name it "loader"
    var loader = Titanium.Network.createHTTPClient();
    // Sets the HTTP request method, and the URL to get data from
    loader.open("GET","http://gdata.youtube.com/feeds/api/users/sample/uploads?v=2&format=5&alt=json&max-results=10");
    // Runs the function when the data is ready for us to process
    loader.onload = function() 
    {
        var data = eval('('+this.responseText+')');
        var items = data.feed.entry || [];

        for (var i = 0; i < items.length; i++)
        {
            //var item = items[i];
            var author = items[i].author[0].name.$t; // The screen name of the user
            var thumbnail = items[i].media$group.media$thumbnail[0].url; 

            // Create a row and set its height to auto
            var row = Titanium.UI.createTableViewRow({height:'auto'});
            //Titanium.API.debug(items);

            var post_view = Titanium.UI.createView({
                height:'auto', 
                layout:'vertical',
                top:5,
                right:5,
                bottom:5,
                left:5
            });
            // Create image view to hold profile pic
            var image = Titanium.UI.createImageView({
                url:thumbnail, // the image for the image view
                top:0,
                left:0,
                height:48,
                width:48
            });
            post_view.add(thumbnail);
            // Create the label to hold the screen name
            var auth = Titanium.UI.createLabel({
                text:author,
                left:54,
                width:120,
                top:-48,
                bottom:2,
                height:16,
                textAlign:'left',
                color:'#444444',
                font:{fontFamily:'Trebuchet MS',fontSize:14,fontWeight:'bold'}
            });
            post_view.add(auth);

            // Add the post view to the row
            row.add(post_view);
            // Give each row a class name
            row.className = "item"+i;
            // Add row to the rowData array
            rowData[i] = row;

        }
        // Create the table view and set its data source to "rowData" array
        var tableView = Titanium.UI.createTableView(row);

        //Add the table view to the window
        winYoutube.add(tableView);
    };
    // Send the HTTP request
    loader.send();
}
loadYoutube();
— asked July 9th 2010 by Rene Cabrera
  • json
  • youtube
0 Comments

3 Answers

  • Youtube clips does not run in simulator. The simulator does not have the youtube application. You will need to test it on the device.

    — answered July 10th 2010 by Dan Tamas
    permalink
    0 Comments
  • I understand that Youtube clips do not run in the simulator. At this point, I am just trying to get the Youtube data like the clip title, thumbnail, description, etc… to display in the table view. I know the JSON data is there but why is it not displaying when I test the app? I can get twitter JSON data to display without a problem. Thoughts?

    — answered July 10th 2010 by Rene Cabrera
    permalink
    0 Comments
  • try instead of this:

    var data = eval('('+this.responseText+')');
    

    to use

    http://developer.appcelerator.com/apidoc/desktop/latest/Titanium.JSON.parse-method

    — answered July 10th 2010 by Dan Tamas
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.