Alejandro
Alejandro

Reputation: 11

FB.api("/me/apprequests/?request_ids="+ids) returning empty data

Im using javascript SDK to send some invitations to friends, and i neeed to get the friends IDs. this is part of my code:

 function RequestFriendship() {
        FB.getLoginStatus(function (response) {
            if (response.session && response.perms != null && response.perms.indexOf('user_about_me') != -1) {
                Request();

            }
            else {
                FB.ui({
                    method: 'auth.login',
                    perms: 'user_about_me,publish_stream',
                    display: 'iframe'
                }, function (response3) {
                    if (response3 != null && response3.perms != null && response3.perms.indexOf('user_about_me') != -1) {

                        Request();

                    }
                    else {
                        alert('No invitations sent.');
                    }
                });
            }
        });

and my Request method is:

 function Request() {

        FB.ui({ method: 'apprequests', message: 'Mensaje Publicidad', data: '', title: 'Titulo publicidad' },
            function (response) {

                if (response && response.request_ids) {
                    var ids = response.request_ids;

                    FB.api("/me/apprequests/?request_ids=" + ids[0], function (response2) {
                        alert(JSON.stringify(response2, replacer));

                    });

                }
            });
    }

But every time run it i get an empty data in the FB.api("/me/apprequests/?request_ids=" + ids[0]. I dont know what im doing wrong, i think i worked fine for me some time ago but now it isnt. Is this a permission problem? I think user_about_me is enough to ask for apprequest but not sure anymore. Any help? Thanx

Upvotes: 0

Views: 7283

Answers (2)

Adrian
Adrian

Reputation: 1054

You don't actually need to create a batch request. You can use the ids parameter on the root and give it the request_ids value returned from the dialog directly:

FB.api("/?ids=" + response.request_ids, callback);

Upvotes: 0

Alejandro
Alejandro

Reputation: 11

WEll i found the answer myself. Just use this:

                if (response && response.request_ids) {
                    var ids = response.request_ids;

                    var _batch = [];
                    for (var i = 0; i < ids.length; i++) {
                        _batch.push({ "method": "get", "relative_url": ids[i] });
                    }
                    if (_batch.length > 0) {
                        FB.api('/', 'POST', { batch: _batch }, function (res) {
                            // var obj = eval('(' + res + ')');

                            for (var j = 0; j < res.length; j++) {
                                body = res[j].body;
                                var myObject = eval('(' + body + ')');
                                friendID = myObject.to.id;
                               // here you have every friendID

                            }
                        });
                    }

                }

:)

Upvotes: 1

Related Questions