Created
August 23, 2011 21:30
-
-
Save appcdr/1166631 to your computer and use it in GitHub Desktop.
Appcelerator: Facebook photo albums sample app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var mainWindow, tableview; | |
function setupWindow() { | |
mainWindow = Titanium.UI.createWindow({ | |
title : 'Tab 1', | |
backgroundColor : '#fff' | |
}); | |
// create table view | |
var tableViewOptions = { | |
data : [] | |
}; | |
if(Ti.Platform.osname == "iphone") { | |
tableViewOptions = { | |
data : [], | |
backgroundColor : 'transparent', | |
rowBackgroundColor : 'white' | |
}; | |
} | |
tableview = Titanium.UI.createTableView(tableViewOptions); | |
// add table view to the window | |
mainWindow.add(tableview); | |
mainWindow.open(); | |
} | |
function getAlbumCovers() { | |
Ti.API.debug(Titanium.Facebook.accessToken); | |
Titanium.Facebook.requestWithGraphPath('me/albums', { | |
fields : 'id,name,cover_photo,count,created_time' | |
}, 'GET', function(e) { | |
if(e.success) { | |
Ti.API.debug(e.result); | |
if(e.result) { | |
var data = JSON.parse(e.result).data; | |
for(x in data) { | |
Ti.API.debug(JSON.stringify(data[x])); | |
var row = Titanium.UI.createTableViewRow({ | |
width : '100%', | |
height : 'auto' | |
}); | |
var image = Titanium.UI.createImageView({ | |
image : "https://graph.facebook.com/" + (data[x].cover_photo || 0) + "/picture?access_token=" + Ti.Facebook.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 : '110dp', | |
width : 'auto', | |
height : 'auto' | |
}); | |
row.add(image); | |
row.add(title); | |
tableview.appendRow(row); | |
} | |
} | |
} else if(e.cancelled) { | |
Ti.API.debug("user cancelled"); | |
} else { | |
Ti.API.debug(e.result); | |
} | |
}); | |
} | |
function initializeFacebookSample() { | |
setupWindow(); | |
Titanium.Facebook.appid = "134793934930"; | |
Titanium.Facebook.permissions = ['publish_stream', 'read_stream', 'user_photos', 'friends_photos']; | |
if(!Titanium.Facebook.loggedIn) { | |
Titanium.Facebook.authorize(); | |
Titanium.Facebook.addEventListener('login', function(e) { | |
if(e.success) { | |
getAlbumCovers(); | |
return; | |
} else if(e.error || e.cancelled) { | |
return; | |
} | |
}); | |
} else { | |
getAlbumCovers(); | |
} | |
} | |
initializeFacebookSample(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment