【问题标题】:Request dialog using facebook使用 facebook 请求对话框
【发布时间】:2011-10-21 15:01:19
【问题描述】:

我正在使用请求对话框向我的朋友发送申请请求。

现在,我想通过 URL 嵌入我的 id,所以当他点击邀请时,它必须
带他到我的应用程序,应该会在我的浏览器地址栏中获得这样的链接:apps.facebook.com/test?uid=1111111111

这个 uid 是我的 uid,因为我把邀请发给了我的朋友。

如何做到这一点? 2011 年 10 月 21 日更新

<script>
  FB.init({
    appId  : 'YOUR_APP_ID',
    status : true,
    cookie : true,
    oauth: true
  });


  function sendRequestToManyRecipients() {
    FB.ui({method: 'apprequests',
      message: 'My Great Request',
    }, requestCallback);
  }

  function requestCallback(response) {
    // Handle callback here
  }
  function getMultipleRequests(requestIds) {
  FB.api('', {"ids": requestIds }, function(response) {
  console.log(response);
});
}
</script>

【问题讨论】:

  • 当他们点击请求时,您的 id 已经在 request_id 中,您可以从那里读取。你想达到什么目的?
  • @ifaour:更新了我的问题。我在哪里把 request_ids 放在我的代码中。

标签: facebook


【解决方案1】:

Request Dialog properties 中,有一个属性data 可用于嵌入您的唯一标识符。

当用户点击邀请通知时,将返回一个(或多个,如果多个朋友邀请他)request_ids。然后就可以使用request_ids查询data了。

更新:将data 放入请求中:

 FB.ui({method: 'apprequests',
      message: 'My Great Request',
      data: 'hello'
    }, requestCallback);

更新2

FB邀请有几个步骤:

1) 该函数打开一个对话框供用户(例如用户A)选择要邀请的朋友:

 FB.ui({method: 'apprequests',
      message: 'My Great Request',
      data: 'hello'
    }, requestCallback);

2) 用户 A 邀请朋友后,用户 B 说,用户 B 将在他的新闻提要上收到通知。

3) 用户 B 点击通知,并被重定向到画布页面:apps.facebook.com/test?request_ids=xxxxxx

4) 您可以使用request_ids 检索邀请详细信息,或者通过 javascript

function getMultipleRequests(requestIds) {
  FB.api('', {"ids": requestIds }, function(response) {
  console.log(response);
});
}

或通过服务器代码(此处为 php,但其他语言的机制相同):

//get the request ids from the query parameter
   $request_ids = explode(',', $_REQUEST['request_ids']);

   //build the full_request_id from request_id and user_id 
   function build_full_request_id($request_id, $user_id) {
      return $request_id . '_' . $user_id; 
   }

   //for each request_id, build the full_request_id and delete request  
   foreach ($request_ids as $request_id)
   {
      echo ("reqeust_id=".$request_id."<br>");
      $full_request_id = build_full_request_id($request_id, $user_id);  
      echo ("full_request_id=".$full_request_id."<br>");

      try {
         $delete_success = $facebook->api("/$full_request_id",'DELETE');
         if ($delete_success) {
            echo "Successfully deleted " . $full_request_id;}
         else {
           echo "Delete failed".$full_request_id;}
        }          
      catch (FacebookApiException $e) {
      echo "error";}
    }

【讨论】:

  • Long:更新了我的问题。我在哪里把 request_ids 放在我的代码中。
  • @user1000990:我已经更新了答案。关于 request_ids,它将作为请求参数返回到您的回调 url。
  • Hoang Long:如何传递请求参数并获取发件人 uid?
  • @user1000990:示例代码在页面末尾:developers.facebook.com/docs/reference/dialogs/requests。有php、javascript等的例子。
  • Long:我更新了我的问题。我已经添加了该脚本,但没有给我请求 ID
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多