我正在尝试修改一个 jQuery 脚本,通过相册 ID 绘制 Facebook 照片。
看来它只拉出了相册中的第一张图片。
如何将“获取”过程修改为随机图像而不是顺序图像?
jQuery:
$.fn.fbPhotos = function(album, limit) {
function base_append(obj) {
$(base).append(obj);
}
function getPhoto(obj) {
var id = obj.id;
var img = obj.img;
var link = obj.link;
var wrap = $('<div></div>').attr({
'class': 'fb-photo',
'id': id
});
var avatar = new Image();
avatar.src = img;
var _avatar = $('<a></a>').attr('href', link).attr('target', '_blank').attr('class', 'avatar').html(avatar);
$(wrap).append($(_avatar));
return wrap;
}
function init() {
fetch();
}
function fetch() {
var r;
var data = {};
$.ajax({
url: 'https://graph.facebook.com/' + albumId + '/photos?limit=' + topLimit,
type: 'GET',
dataType: 'jsonp',
data: data,
success: function(obj) {
// console.log(obj);
if (obj.error) {
/* var img = new Image();
img.src = theme_url + '/images/ico_fail_bird.png';
wipe(img); */
return false;
其余的在jsFiddle
最佳答案
您无法使用 Graph API 来完成此操作,但可以使用 FQL photo table 来完成此操作。在 fetch
函数中更改此行:
url: 'https://graph.facebook.com/fql?q=SELECT+src+FROM+photo+WHERE+album_object_id="'
+ albumId + '"+ORDER+BY+rand()+LIMIT+' + topLimit,
关于javascript - 从 FB 相册中随机抽取图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14548312/