Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (pictures)
Viewing all articles
Browse latest Browse all 9

Get pictures from facebook albums

0
0

Application Type:mobile,Titanium sdk:3.3.0 GA,platform :Android and ios,OS:Mac OSX 10.9.3,Titanium studi:3.3

How to get pictures from facebook albums:

I tried this code(not written by me)got from the link: http://www.appcelerator.com/blog/2011/08/titanium-quickie-facebook-album-covers-part-1/

I got the album and the cover photo.If I click on the album how to get the photos in that album.?

(function() {
    var fb = require('facebook');
    fb.appid = "29726********08";
// Getting permissions
fb.permissions = ['publish_stream', 'read_stream', 'user_photos', 'friends_photos'];
// Login to facebook
fb.addEventListener('login', function(e) {
        if(e.success) {
            // function call after successful login.
            getAlbumCovers();
            return;
        } else if(e.error || e.cancelled) {
            return;
        }
    });
     var mainWindow = Ti.UI.createWindow({
            title : 'Tab 1',
            backgroundColor : '#fff'
        })
        ,
        tableview = Ti.UI.createTableView({
            backgroundColor : 'transparent',
            rowBackgroundColor : 'white'
        })
        ,
        activityIndicator = Ti.UI.createActivityIndicator({
            message:' Loading...',
        })
        ,
        fb_button = fb.createLoginButton();
 
    function setupWindow() {
        mainWindow.add(activityIndicator);
        if(!fb.loggedIn) {
 
            mainWindow.add(fb_button);
 
        } else {
            mainWindow.remove(fb_button);
            getAlbumCovers();
            mainWindow.add(tableview);
        }
 
        mainWindow.open();
    }
 
function getAlbumCovers() {
        activityIndicator.show();
 
// Graph API call
        fb.requestWithGraphPath('me/albums', {
            fields : 'id, name, count, type'
        }, 'GET', function(e) {
 
            if(e.success) {
 
                Ti.API.debug(e.result);
 
                if(e.result) {
 
                    var rows = [];
 
                    var data = JSON.parse(e.result).data;
 Ti.API.info(fb.accessToken);
 
                    for(x in data) {
                        a=x;
                        Ti.API.debug(JSON.stringify(data[x]));
 
                        var row = Titanium.UI.createTableViewRow({
                            width : '100%',
                            height : 'auto',
                            id: a,
                        });
                        var fbimage = Titanium.UI.createImageView({
                            image :  "https://graph.facebook.com/" + (data[x].id || 0) + "/picture?access_token=" +fb.accessToken,
                            top : 0,
                            left : 0,
                            width : 100,
                            height : 100
                        });
                        var title = Titanium.UI.createLabel({
                            text : String.format("%s (%d)", data[x].name, data[x].count),
                            top : 0,
                            left : 110,
                            width : 'auto',
                            height : 'auto'
                        });
                        Ti.API.info((data[x].id));
 
// I am trying to get pics using this array
                        var array = [];
                            var array = "https://graph.facebook.com/" + (data[x].id || 0) + "/photos";
                        row.addEventListener('click', function(ev){
 var pic=JSON.parse(e.result);
               alert(pic.data.length);//getting 0 in alert.even photos are there in the album
                          });
 
 
                    tableview.setData(rows);
                }
 
            } else if(e.cancelled) {
              //  Ti.API.debug("user cancelled");
            } else {
                Ti.API.debug(e.result);
            }
            activityIndicator.hide();
        });
    }
 setupWindow();
 
})();

Viewing all articles
Browse latest Browse all 9

Latest Images

Trending Articles





Latest Images