如何发送Facebook应用程序请求以检索接受数据?

时间:2012-10-31 04:24:51

标签: php facebook facebook-graph-api

需要发送Facebook应用程序请求,以便当用户接受请求时,我需要检索发送请求的人的姓名以及接受该请求的人的姓名。有人可以分享一下鳕鱼的例子

2 个答案:

答案 0 :(得分:2)

发送邀请时,您可以添加任何数据进行跟踪,假设您要发送sender_name,以便您的发送请求功能如下:

FB.ui({
        method: 'apprequests',
        message: "has invited you to the app",
        filters:['app_non_users'],
        data: sender_name
    }, function (response) {
    });

当接收方点击发送的请求通知到您的应用程序时,您可以检索数据并在php中删除请求,如下所示:

if(isset($_GET['request_ids']))
   {
       $request_ids = $_GET['request_ids'];
       $request_ids = explode(",", $request_ids);
       foreach($request_ids as $request_id)
            {
                 $request_object = $facebook->api($request_id);
                 if(isset($request_object['data'])) $req_data = $request_object['data'];//you can now use the sent $req_data your way
                 $full_request_id = $request_id."_".$current_user_fbid;
                 $facebook->api("$full_request_id","DELETE");
            }
   }

答案 1 :(得分:1)

我假设您将使用数据库。当用户邀请朋友时,发送的请求的响应将包含response.request和response.to。将此request_id与用户和用户朋友ID(邀请的朋友)一起存储。

function inviteuser(){
    FB.ui({
        method: 'apprequests',
        message: "Apllications message goes here",
        exclude_ids: [1, 2, 3],
        filters:['app_non_users'],
        data: "optional additional data you may pass for tracking"
    }, function (response) {
        if (response && response.to) {
        //callback function, will be called after user invites his friend, response object will contain list of all users invited
        //save response.to and response.request in database
        }
    });
}

当用户接受邀请,即通过点击应用请求通知进入您的应用程序画布页面时,Facebook会在“request_ids”参数中发送逗号分隔的ID。您可以获取此请求ID并与数据库进行比较以获取所需信息。