Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Facebook : the image is displayed only for last post , how to get all images in table view

$
0
0

Hi

I am trying to pull profile pics from facebook for each person who makes a post on my app.

I am able to get the image links , but for some reason the image is not getting displayed only for the last post.

Can somebody explain what`s wrong or how to load all images?

fb.addEventListener('login', function(e) {
    if (e.success) {
        alert('Logged in');
        Cloud.SocialIntegrations.externalAccountLogin({
            type : 'facebook',
            token : Ti.Facebook.accessToken
        }, function(e) {
            if (e.success) {
                var user = e.users[0];
                Ti.API.info('User  = ' + JSON.stringify(user));
                Ti.App.Properties.setString('currentUserId', user.id);
                alert('Success: ' + 'id: ' + user.id + '\\n' + 'first name: ' + user.first_name + '\\n' + 'last name: ' + user.last_name);
 
 
 
                Cloud.Posts.query(function (e) {
        if (e.success) {
            if (e.posts.length == 0) {
                //alert("There is no information to display. Please enter some data and try again.");
 
                tableView.setData([
                    { title: 'No Results!' }
                ]);
            }
            else {
                var data = [];
                for (var i = 0, l = e.posts.length; i < l; i++) {
 
                    var row = Ti.UI.createTableViewRow({
                        id: e.posts[i].id,
                        height:'90'
 
                    });
 
 
                    var rowView = Titanium.UI.createView({
                        height: '90%',
                        width: 'auto',
                        backgroundColor:'#fdfcfc'
 
                    });
 
                    var rowLabel = Titanium.UI.createLabel({
                        text:e.posts[i].content,
                        //textAlign:'left',
                        top:5,
                        left:55
                    });
 
                    var rowLeftButton = Titanium.UI.createButton({
                        title:'Comment',
                        bottom:0,
                        left:0,
                        width:'50%',
                        height:'40%',
                        backgroundColor:'#d4d2cf',
 
                    });
 
                    var rowRightButton = Titanium.UI.createButton({
                        title:'Share',
                        bottom:0,
                        right:0,
                        width:'50%',
                        height:'40%',
                        backgroundColor:'#d4d2cf'
                    });
                    var borderRight = Ti.UI.createView({
                        backgroundColor: '#e0e0e0',
                        width: 1,
                        top: 0,
                        bottom: 0,
                        right: 0
                    });
                    //var nano = JSON.stringify(e.posts[i]);
                    //var nano = JSON.parse(e.posts[i]);
                    //Titanium.API.info(e.posts[i].user.external_accounts[0].external_id);
 
                    var imageView = Titanium.UI.createImageView({
                        //image:z,
                        left:0,
                        top:0
                    });
 
 
                    fb.requestWithGraphPath(e.posts[i].user.external_accounts[0].external_id+"/picture?redirect=0",{},'GET',function(i){
                        if(i.success){
 
                            var nano = JSON.parse(i.result);
                            //Titanium.API.info(nano.data.url);
                            imageView.image = nano.data.url;
                            Titanium.API.info(nano.data.url);
 
                        }else if(i.error){
                            alert(i.error);
                        }else{
                            alert('Unknown Response');
                        }
                    });
 
 
                    rowView.add(imageView);
                    rowLeftButton.add(borderRight);
                    rowView.add(rowLeftButton);
                    rowView.add(rowRightButton);
                    rowView.add(rowLabel);
                    row.add(rowView);
                    data.push(row);
 
 
                }
                tableView.setData(data);
            }
        }
        else {
            error(e);
        }
    });

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>