Skip to content

Instantly share code, notes, and snippets.

@appcdr
Created August 24, 2011 01:31
Show Gist options
  • Save appcdr/1167102 to your computer and use it in GitHub Desktop.
Save appcdr/1167102 to your computer and use it in GitHub Desktop.
Appcelerator: Facebook photo albums pieces
Titanium.Facebook.appid = "134793934930";
Titanium.Facebook.permissions = [
'publish_stream',
'read_stream',
'user_photos',
'friends_photos'
];
if(!Titanium.Facebook.loggedIn) {
// this will displaty the standard webView login.
Titanium.Facebook.authorize();
Titanium.Facebook.addEventListener('login', function(e) {
if(e.success) {
// FUNCTION TO MAKE API CALL GOES HERE
return;
} else if(e.error || e.cancelled) {
return;
}
});
} else {
// FUNCTION TO MAKE API CALL GOES HERE TOO!! Called if already authenticated
}
Titanium.Facebook.requestWithGraphPath(
'me/albums',
{
fields : 'id,name,cover_photo,count,created_time'
},
'GET',
function(graphResp) {
if(graphResp.success) {
if(graphResp.result) {
var data = JSON.parse(graphResp.result).data;
for (x in data) {
Ti.API.debug(JSON.stringify(data[x]));
// IMAGE VIEW LOOP CREATION CODE GOES HERE
}
}
} else if(graphResp.cancelled) {
alert("User Cancelled");
} else {
Ti.API.debug(graphResp.result);
}
}
);
var imageView = Ti.UI.createImageView({
width:50,
height:50,
left:10,
top:5,
bottom:5,
album_id:data[/*index of album*/].id,
image:'https://graph.facebook.com/'+data[*index of album*/].cover_photo+'/picture?access_token=' + Ti.Facebook.accessToken
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment