使用Titanium发布twitter个人资料图片

时间:2013-02-06 05:06:26

标签: twitter titanium-mobile

我是钛的新手,我正在学习使用钛的JSon Parsing。我正在访问特定屏幕名称的推文以及他/她的个人资料图片。它对推文起到了很好的作用,但没有显示该推文的个人资料图片。

我的Tweet.js文件是:

 // Create variable "win" to refer to current window
 var win = Titanium.UI.currentWindow;
 // Function loadTweets()
 function loadTweets()
 {
// Empty array "rowData" for our tableview
var rowData = [];
var avatar;
// 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://api.twitter.com/1/statuses/user_timeline.json?screen_name=SenchaTouch");
// Runs the function when the data is ready for us to process
loader.onload = function() 
{
    var tweets = eval('('+this.responseText+')');
    alert(tweets);
    for (var i = 0; i < tweets.length; i++)
    {
        var tweet = tweets[i].text; // The tweet message
        var user = tweets[i].user.screen_name; // The screen name of the user
        avatar = tweets[i].user.profile_image_url; // The profile image
        // Create a row and set its height to auto
        var row = Titanium.UI.createTableViewRow({height:'auto'});

        // Create the view that will contain the text and avatar
        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 av_image = Titanium.UI.createImageView({
            url:'KS_nav_ui.png', // the image for the image view
            top:0,
            left:0,
            height:48,
            width:48
        });
        post_view.add(av_image);
        // Create the label to hold the screen name
        var user_lbl = Titanium.UI.createLabel({
            text:user,
            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(user_lbl);
        // Create the label to hold the tweet message
        var tweet_lbl = Titanium.UI.createLabel({
            text:tweet,
            left:54,
            top:0,
            bottom:2,
            height:'auto',
            width:236,
            textAlign:'left',
            font:{fontSize:14}
        });
        post_view.add(tweet_lbl);
        // 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({data:rowData});
    //Add the table view to the window
    win.add(tableView);
};
// Send the HTTP request
loader.send();
   }
   loadTweets();

//能找到任何缺陷吗?任何帮助,将不胜感激。 提前感谢:)

1 个答案:

答案 0 :(得分:2)

最后发现它..问题出在代码中。我只是在图像视图中使用url属性而不是image属性。用url替换image属性已经成功了。

  url: avatar, // It should not be used .. It is not working 
  image: avatar, // It is working very well..