Why does Graph API only return to 25 groups?

Asked

Viewed 106 times

2

I have the second code:

// globals
var blacklist = [];
var appId = '';

function performPostLoginTasks() {
    show_notification('Authorization', 'You successfully logged in using Facebook. Now we can load your groups.');
    $("#get_groups").removeAttr('disabled');
    $("#login").hide();
    getGroups();
}


function login() {

    FB.login(function (response) {
        if (response.authResponse) {
            performPostLoginTasks();
        } else {
            show_notification('Authorization', 'We could not log you in to Facebook. We are very sad that it failed.', 'error');
        }
    }, {scope: 'publish_actions,user_groups'});

}

function loadBlacklist() {

    $.ajax({
        'async': false,
        'global': false,
        'url': 'blacklist.json',
        'dataType': "json",
        'success': function (data) {
            blacklist = data;
        }
    })

}

function filterPost(text) {
    text = text.toLowerCase();
    var x = 0;

    while (x <= (blacklist.length - 1)) {
        if (text.search(blacklist[x]) !== -1) {
            return blacklist[x];
        }
        x++;
    }

    return false;
}

function getGroups() {

    FB.api("/me/groups", function (response) {
        $('#groups')
            .css('overflow-y', 'scroll')
            .css('border', '2px solid #000000')
            .html("<small>(Scroll down to view more)</small><br/><br/>");

        data = response['data'];
        for (var x in data) {
            addCheckbox(data[x].name, data[x].id)
        }

        $("#post").removeAttr('disabled');
        show_notification('Groups', 'Groups loaded. Select a few of them. Write a post and share with the selected groups.', 'notice');

        loadBlacklist();
    });


}

function addCheckbox(name, id) {
    var container = $('#groups');
    var html = '<input type="checkbox" id="cb' + id + '" value="' + id + '" /> <label for="cb' + id + '">' + name + '</label><br/>';
    container.append($(html));
}

function makePost(groupId, message) {

    FB.api("/" + groupId + "/feed", "post", {"message": message,    picture: 'http://imgur.com/IKsWBjD'}, function (resp) {
        if (resp.id) {
            show_notification('Posted', "Posted to: '" + $("#groups").find("label[for=cb" + groupId + "]").html() + "'.", 'success');
        } else {
            show_notification('Failed', "Failed to post to the selected groups.", 'error');
        }
    })

}

function startPosting() {
    var message = $("#msg").val();
    var blackListedWord = filterPost(message);

    if (!blackListedWord) {
        input_list = $("#groups").find('input')
        for (var x in input_list) {
            if (input_list[x].checked) {
                makePost(input_list[x].value, message)
            }
        }
    }
    else {
        show_notification('Blacklisted Word', 'Your post contains the word \'' + blackListedWord
            + '\' which is in our blacklisted word list. Sorry, we can not allow this post!', 'error');
    }


}

function show_notification(title, message, type) {
    //console.log(type);
    switch (type) {
        case undefined:
            $.growl({title: title, message: message });
            break;
        case 'error':
            $.growl.error({title: title, message: message });
            break;
        case 'notice':
        case 'success':
            $.growl.notice({title: title, message: message });
            break;
        case 'warning':
            $.growl.warning({title: title, message: message });
            break;

    }
}

function setAppId() {
    appId = $("#appIdInput").val();
    $('#appIdModal').modal('hide');
    fbAsyncInit();
    var url = "http://super-poster.net/?appId=" + appId
    $("#url").attr('href', url).html(url);
    $("#urlContainer").show();
    $("#login").removeAttr('disabled');
    $("#appIdButton").val('Switch App ID');

}

function getQSParam(sParam) {
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');

    for (var i = 0; i < sURLVariables.length; i++) {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) {
            return sParameterName[1];
        }
    }
}

$(document).ready(function () {

    appId = getQSParam('appId');
    if (appId) {
        if (window.FB) {
            fbAsyncInit();
        }

        var url = "http://super-poster.net/?appId=" + appId
        $("#url").attr('href', url).html(url)

        $("#appIdButton").hide();
        $("#spam-notice").hide();
        $("#login").removeAttr('disabled');
    } else {
        $("#urlContainer").hide();
    }


});

But, it returns to only 25 groups.. how do I catch the rest? And taking advantage, as put an image?

FB.api("/" + groupId + "/feed", "post", {"message": message,    picture: 'http://imgur.com/IKsWBjD'}, function (resp) {

Tag picture shows a link.. Obg,

2 answers

1

Beyond the object date the object is also returned paging, and if the user has more than 25 groups the object paging will contain the "next" and "Previous" property containing a url to the next/previous page. Just request them via ajax.

Regarding posting image, you need to call the "/me/photos/" method. Take a look at the documentation: https://developers.facebook.com/docs/graph-api/reference/user/photos

1


Use the limit parameter in your request. I think it has a maximum of 5000 items per page.

Example:

FB.api("/"+ idGrupo +"/members/?limit=5000", pegarUsuarios);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.