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

How do you retrieve photos from ACS and display them on app?

$
0
0

Hi. I'm a newbie in Titanium and web development. I uploaded some images to the Titanium Cloud Service (ACS) and wanna display them on my app. Below is my code. It runs, but I don't see any photos except for the title and back button. Can someone take a look at my code and give me some hint on what I'm missing? Thank you for your time!

//Import the module
var Cloud = require('ti.cloud');
Cloud.debug = true;  // optional; if you add this line, set it to false for production 
 
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
 
exports.getAlbumWin = function() {
 
    //create window
    var album_window = Titanium.UI.createWindow({
        backgroundColor:'#FFF',
        title: "Travel Diary"
    });
 
    //create title
    var title = Titanium.UI.createLabel({
        text: "All Trip Photos Submitted by Our Users",
        top:10,
        color: '#008000',
        textAlign: 'center',
        font: {fontSize:50}
    });
 
 
    var tableView = Ti.UI.createTableView({
        top: '5%',
        scrollable: true,
        width: '100%',
        minRowHeight: '500',
        bottom: '10%',
    });
 
 
    //Get diary entries, add them to the table view and display it  
    Cloud.Photos.query({
       page: 1,
       per_page: 10
    }, function(e) {
        var row, dateLabel, placeLabel, reviewLabel;
        var displayData = [];
 
        if (e.success){    
            alert('Count: '+e.photos.length);
 
            for (var i=0; i<e.photos.length; i++) {
                var photo = e.photos[i];
 
                var image2 = photo.urls.square.toImage();
                //create imageView
                var photoView = Ti.UI.createImageView({
                    image: image2
                });
                //photo.urls.square
 
                displayData.push(photoView);
            }
 
            tableView.setData(displayData);
        } else {
            alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
        }   
    });
 
    //add a 'back' button
    var back_button = Titanium.UI.createButton({
        title: "Back",  
        height:160,
        left:40,
        right:40,
        bottom: '0%'    
    });     
 
    //Add Event Listener
    back_button.addEventListener('click', function(){
        //call an export function
        var win = require('home').getHomeWin;
 
        //create new instance
        var nextWin = new win();
        nextWin.open();
    });
 
    album_window.add(title);
    album_window.add(tableView);
    album_window.add(back_button);
    return album_window;
};

Viewing all articles
Browse latest Browse all 8068

Trending Articles