2011-02-26 42 views
6

我正在使用「請求對話框」來創建Facebook請求。爲了讓用戶發送請求,我需要使用圖形API訪問Request對象。我嘗試了大部分似乎合適的權限設置(read_requests和user_about_me)來獲取請求對象,但我在響應中得到了一個錯誤。我使用錯誤的權限?FaceBook API:獲取請求Id的請求對象 - 登錄到發送請求的帳戶。使用「請求對話框」API

我能夠使用圖形API從發送請求的帳戶訪問請求對象。

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

返回數據 - 逗號分隔的列表中創建的request_ids的 。 要了解誰發送了請求,請將 發送給,您應循環處理由請求標識標識的每個請求對象 的 信息。

+0

你可以發佈你正在做的確切的調用和你得到的輸出嗎? – 2011-02-26 19:24:24

+0

'GET/RequestID /'是具有權限'read_requests'或'user_about_me'返回false的圖形API調用,而不是請求對象。 – ak7 2011-02-28 14:38:45

+0

任何使用目標用戶的提示可能是什麼?我們不知道他們在登錄時是誰的朋友,我們可以驗證他們的朋友列表與現有用戶fbids嗎? – Kevin 2012-08-26 01:41:06

回答

4

我一直在問自己這個問題前一段時間:
如何檢索所有的請求由我發送

答案:你不能
你有兩個選擇:

  1. 存儲時,用戶發送的請求request_id返回,這樣你就可以在以後訪問他們,並得到這些數據,您需要
  2. 知道了接收器!

證明以上內容,您可以查看friend_request表。可轉位字段是uid_to字段!

0

如果您想查找剛剛發送請求的用戶的用戶ID,然後,這個代碼是你所需要的:

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 
     }); 
    } 
}); 
0

不知道這是否會有所幫助,但這裏是我如何處理它。

的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; 
    } 

服務器端(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... 
       } 
      } 
     } 
1

這是,如果你想在知道的iFrame模式你不需要的iFrame模式更多

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; 
    } 
0

您可以訪問用戶標識列表作爲返回數據的一部分

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