开发者

FaceBook API: Get the Request Object for a request Id - logged into the account that sent the request. Using the "Requests Dialog" API

I am using the "Requests Dialog" to create Facebook requests. Inorder to get the user that the requests were sent to I need to access the Request object using the graph API. I have tried most of the permissions settings that seemed appropriate (read_requests and user_about_me) to get the request object, but instead I get a false in the response. Am I using the wrong permissions?

I am able to access the request object using the graph API from the account that the request was sent to.

http://developers.facebook.com/docs/reference/dialogs/requests/

Return Data - A comma-separated list of the request_ids that were created. To learn who the requests were sent 开发者_StackOverflow社区to, you should loop through the information for each request object identified by a request id.


I've been asking myself this question a while ago:
How to retrieve all the requests sent by me?

The answer: you can't!
You have two options:

  1. Store the request_id returned when the user sent the request, so you can later access them and get the data you need
  2. Knowing the receiver!

Proof of the above, you can check the friend_request table. The indexable field is the uid_to field!


This is if you want it in know Iframe mode as you don't need Iframe mode any more

function sendRequest() {
        FB.ui({                    
            method: 'apprequests',
            title: 'Invite friends to join you',
            message: 'Come play with me.'
            },
            function (res) {
                if (res && res.request_ids) {
                    var requests = res.request_ids.join(',');
                    $.post('FBRequest.ashx',
                        { request_ids: requests },
                        function (resp) { });                    
                }
            });
        return false;
    }


If you want to find out the user ids of the people you just sent a request to. Then this code is what you need:

var request = {
    message: msg,
    method: 'apprequests',
    title: 'Select some of your friends'
};
FB.ui(request, function (data) {
    if (data && data.request_ids) {

        // Get the uid of the person(s) who was/were invited
        var uids = new Array();
        FB.api("/?ids=" + data.request_ids.join(), function(data2) {
            for (i = 0; i<data.request_ids.length; i++) {   
                uids[i] = data2[data.request_ids[i]]['to']['id']; 
            }
            # do something with uids here
        });
    }
});


Don't know if this helps, but here's how I handle it.

Javascript:

    function sendRequest() {
        FB.ui({
            display: 'iframe',                    
            method: 'apprequests',
            title: 'Invite friends to join you',
            message: 'Come play with me.'
            },
            function (res) {
                if (res && res.request_ids) {
                    var requests = res.request_ids.join(',');
                    $.post('FBRequest.ashx',
                        { request_ids: requests },
                        function (resp) { });                    
                }
            });
        return false;
    }

Server side (FBRequest.ashx):

        // get operation and data
        var ids = HttpContext.Current.Request["request_ids"];

        // if we have data
        if(ids != null) {

            // make batch graph request for request details
            var requestIds = ids.Split(',').Select(i => long.Parse(i)).ToList();
            var fbApp = new FacebookWebClient([AppId],[AppSecret]);
            dynamic parameters = new ExpandoObject();
            parameters.ids = ids;
            dynamic requests = fbApp.Get(parameters);

            // cycle through graph results and do stuff
            dynamic req = null;
            for(int i=0;i<requestIds.Count;i++) {
                try {
                    req = requests[requestIds[i].ToString()];
                    // do stuff with request, save to DB, etc.
                } catch (Exception ex) {
                    // error in finding request, continue...
                }
            }
        }


You can access the list of user id's as part of the return data

FB.ui({
  method: 'apprequest',
  message: 'Use this thing',
}, function(result){
      //a list of ids are in here
      result.to;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜