javascript - 从 FB 相册中随机抽取图片

标签 javascript jquery facebook slider

我正在尝试修改一个 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/

相关文章:

javascript - App Engine 和 Facebook : which libraries to use?

php - jquery $.post 从 php 返回的数据为空

facebook - 如何获取在 Facebook 中签到某个地方的人员列表

facebook - 我可以在 Facebook 主页上使用 facepile 吗?

javascript - 无法使用ajax上传文件

javascript - 将文本和图像组合成一个 "entity"

javascript - 设置复选框值

javascript - 如何根据列表中是否有其他项目显示按钮?

Facebook : How to show the Facebook page likes count and Like button to like the Facebook page?

javascript - 如果我的任何 switch case 匹配,我如何运行附加功能?