Getting Facebook profile Album without Iterating through every profile albums -
function getalbumcovers() { //first check see if profile pics exist in user model //create collection var userscollection = alloy.collections.user; facebookmodule.requestwithgraphpath('me/albums', { fields : 'id,name,cover_photo,count,created_time' }, 'get', function(graphresp) { //show view indicator before data fetched //$.view_indicator.visible = true; setviewindicator(100, 100, levelcolour, 10, true, '30%'); $.ind.top = '30'; if (graphresp.success) { if (graphresp.result) { var rows = []; var data = json.parse(graphresp.result).data; var = 0; var blob; (x in data) { if (data[x].name == "profile pictures") { ti.api.debug(json.stringify(data[x])); var numberphotos = null; var albumtitle = null; //apply transformations if (data[x].count == null) { numberphotos = 0; } else { numberphotos = data[x].count; if (numberphotos > 10) { numberphotos = 10; } else { numberphotos = numberphotos; } } albumtitle = data[x].name + ' (' + numberphotos + ')'; console.log("https://graph.facebook.com/" + (data[x].cover_photo || 0) + "/picture?access_token=" + alloy.globals.facebookmodule.accesstoken + "&type=album"); //start // read image blob var url = "https://graph.facebook.com/" + (data[x].cover_photo || 0) + "/picture?access_token=" + alloy.globals.facebookmodule.accesstoken + "&type=album"; var imgview = ti.ui.createimageview({ image : url, width : 'auto', height : 'auto' }); var imgblob = imgview.toblob(); var height = imgblob.height; var width = imgblob.width; if (height > width) { var pos = (height - width) / 2; var dict = { height : width, width : width, x : 0, y : pos }; var newimg = imgblob.imageascropped(dict); //alert(newimg.height); } else if (height < width) { var pos = (width - height) / 2; var dict = { height : height, width : height, x : pos, y : 0 }; var newimg = imgblob.imageascropped(dict); //alert(newimg.width); } else { //alert(imgblob.width + '-' + imgblob.height); var pos = (width - height) / 2; var dict = { height : height, width : height, x : pos, y : 0 }; var newimg = imgblob.imageascropped(dict); } imgblob = null; //end var row = titanium.ui.createtableviewrow({ titlealb : data[x].name, selectedbackgroundcolor : 'transparent', selectionstyle : 'titanium.ui.iphone.tableviewcellselectionstyle.none on createtableviewrow', width : '100%', height : '60' }); var image = titanium.ui.createimageview({ //image : "https://graph.facebook.com/" + (data[x].cover_photo || 0) + "/picture?access_token=" + alloy.globals.facebookmodule.accesstoken + "&type=album", image : newimg, top : 10, bordercolor : levelcolour, left : 30, width : '40', height : '40' }); if (alloy.globals.platform == 'old') { var title = titanium.ui.createlabel({ text : albumtitle, font : { visible : true, color : '#888888', fontfamily : 'avenir-roman', size : 12, }, width : 200, top : 15, color : levelcolour, right : '30dp', height : 'auto' }); } else if (alloy.globals.platform == '6') { var title = titanium.ui.createlabel({ text : albumtitle, font : { visible : true, color : '#888888', fontfamily : 'avenir-roman', size : 12, }, width : 200, top : 15, color : levelcolour, right : '85dp', height : 'auto' }); } else if (alloy.globals.platform == '6+') { var title = titanium.ui.createlabel({ text : albumtitle, font : { visible : true, color : '#888888', fontfamily : 'avenir-roman', size : 12, }, width : 200, top : 15, color : levelcolour, right : '105dp', height : 'auto' }); } row.add(image); row.add(title); rows.push(row); i++; console.log(i); //set table rows $.tableview.setdata(rows); //end $.view_indicator.visible = false; break; } } } } else { $.view_indicator.visible = false; if (e.error) { alert(e.error); } else { alert("unkown result"); } } }); }
here code, can see having calling facebook api graph iterating through every album, , detecting profile album. problem approach if user has 1000 albums, loop can take forever find profile album.
anyone know of quicker way this?
cheers
currently there no such mechanism available in graph api.
also, proposed method unreliable @ best, since not uses facebook in english language, , don't, album might not called "profile pictures".
the best way user's current profile picture (without album) fetching /user/picture
Comments
Post a Comment