获取Facebook个人资料相册而无需遍历每个个人资料相册 函数getAlbumCovers(){ //首先检查用户模型中是否已经存在配置文件图片 //创建一个集合 var userscolection=Alloy.Collections.user; fa
获取Facebook个人资料相册而无需遍历每个个人资料相册 函数getAlbumCovers(){ //首先检查用户模型中是否已经存在配置文件图片 //创建一个集合 var userscolection=Alloy.Collections.user; facebookModule.requestWithGraphPath('me/albums'{ 字段:“id、姓名、封面照片、计数、创建时间” }“获取”函数(graphResp){ //在提取数据之前显示视图指示器 //$.view\u indicator.visible=true; setViewIndicator(100、100、LevelColor、10、true、“30%”); $.ind.top='30'; 如果(图形成功){ 如果(图形结果){ var行=[]; var data=JSON.parse(graphResp.result).data; var i=0; var-blob; 对于(数据中的x){ 如果(数据[x].name==“个人资料图片”){ debug(JSON.stringify(data[x]); var numberPhotos=null; var-title=null; //应用变换 如果(数据[x]。计数==null){ numberPhotos=0; }否则{ numberPhotos=数据[x]。计数; 如果(数字照片>10){ 数字照片=10; }否则{ numberPhotos=numberPhotos; } } albumTitle=data[x].name+'('+numberPhotos+'); 控制台日志(“https://graph.facebook.com/“+(数据[x]。封面照片| | 0)+”/picture?访问令牌=“+Alloy.Globals.facebookModule.accessToken+”&type=album”); //开始 //以水滴的形式读取图像 变量url=”https://graph.facebook.com/“+(数据[x]。封面照片| | 0)+”/picture?访问令牌=“+Alloy.Globals.facebookModule.accessToken+”&type=album”; var imgView=Ti.UI.createImageView({ 图片:url, 宽度:“自动”, 高度:“自动” }); var imgBlob=imgView.toBlob(); 变量高度=imgBlob.height; 变量宽度=imgBlob.width; 如果(高度>宽度){ 变量位置=(高度-宽度)/2; 变量dict={ 高度:宽度, 宽度:宽度, x:0,, y:位置 }; var newImg=imgBlob.imagescropped(dict); //警报(新高度); }否则如果(高度<宽度){ 变量位置=(宽度-高度)/2; 变量dict={ 高度:高度,, 宽度:高度, x:pos, y:0 }; var newImg=imgBlob.imagescropped(dict); //警报(新宽度); }否则{ //警报(imgBlob.width+'-'+imgBlob.height); 变量位置=(宽度-高度)/2; 变量dict={ 高度:高度,, 宽度:高度, x:pos, y:0 }; var newImg=imgBlob.imagescropped(dict); } imgBlob=null; //结束 var row=tianium.UI.createTableViewRow({ titleAlb:data[x]。名称, selectedBackgroundColor:“透明”, selectionStyle:'Titanium.UI.iPhone.TableViewCellSelectionStyle.NONE on createTableViewRow', 宽度:“100%”, 身高:'60' }); var image=tianium.UI.createImageView({ //图像:“https://graph.facebook.com/“+(数据[x]。封面照片| | 0)+”/picture?访问令牌=“+Alloy.Globals.facebookModule.accessToken+”&type=album”, 图片:newImg, 前10名, 边框颜色:LevelColor, 左:30,, 宽度:'40', 身高:'40' }); if(Alloy.Globals.Platform=='old'){ var title=Titanium.UI.createLabel({ 文字:专辑名称, 字体:{ 可见:对, 颜色:“#888888”, fontFamily:“Avenir Roman”, 尺码:12, }, 宽度:200, 前15名, 颜色:LevelColor, 右图:“30dp”, 高度:“自动” }); }else if(Alloy.Globals.Platform=='6'){ var title=Titanium.UI.createLabel({ 文字:专辑名称, 字体:{ 可见:对,获取Facebook个人资料相册而无需遍历每个个人资料相册 函数getAlbumCovers(){ //首先检查用户模型中是否已经存在配置文件图片 //创建一个集合 var userscolection=Alloy.Collections.user; fa,facebook,facebook-graph-api,Facebook,Facebook Graph Api,获取Facebook个人资料相册而无需遍历每个个人资料相册 函数getAlbumCovers(){ //首先检查用户模型中是否已经存在配置文件图片 //创建一个集合 var userscolection=Alloy.Collections.user; facebookModule.requestWithGraphPath('me/albums'{ 字段:“id、姓名、封面照片、计数、创建时间” }“获取”函数(graphResp){ //在提取数据之前显示视图指示器 //$.view\u ind
function getAlbumCovers() {
//first check to see if profile pics already exist in user model
//create a 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 is 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 i = 0;
var blob;
for (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 the image as a 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");
}
}
});