2011-11-24 69 views
2

我想要做的是獲取請求ID並插入到我的數據庫。我的請求對話框運行良好,但問題是我無法獲取'TO'用戶標識http://developers.facebook.com/docs/reference/dialogs/requests/,但我仍然無法獲取請求用戶標識。如何獲取Facebook請求對話框上的用戶ID

這裏是我的編碼:

  function newInvite(){ 
      //var user_ids = document.getElementsByName("user_ids")[0].value; 
      FB.ui({ 
        method : 'apprequests', 
        title: 'X-MATCH', 
        message: 'Come join US now, having fun here',      
      },      
      function getMultipleRequests(requestIds) { 
       FB.api('', {"ids": requestIds }, function(response) { 
       console.log(response); 
       }); 
      }     
      ); 
     } 

對此有什麼解決辦法嗎?

百萬感謝您的幫助

回答

4

您是否啓用請求2.0有效?

如果已經啓用了,你可以很容易地獲取用戶id作爲這樣

{ 
    request: ‘request_id’ 
    to:[array of user_ids] 
} 

在回調函數的響應,你可以使用

response.request獲得請求ID

response.to以獲得用戶ID數組

並注意,如果您使用請求2.0,請求ID格式將這樣

<request_object_id>_<user_id> 

如果不啓用它,那麼你只能獲得請求ID的數組,你需要另一個API調用來獲取用戶ID

編輯:

FB.ui({ 
     method : "apprequests", 
     title : "your title", 
     message : "your msg" 
     }, 
     function(response) { 
      var receiverIDs; 
      if (response.request) { 
       var receiverIDs = response.to; // receiverIDs is an array holding all user ids 
      } 
     } 
); 

然後可以使用陣列「receiverIDs」用於進一步的處理

例如我發送給ID爲「1234」的用戶ID的請求時, 「5678」

的響應將是這樣的:

{ 
    request: ‘1234567890’ // example, 
    to:['1234', '5678'] 
} 

在要求2.0,完整的請求ID看起來像這樣

1234567890_1234 
1234567890_5678 

注意:FB DOC告訴您管理和刪除請求自己,如果您使用請求2.0, 請記得刪除上面的id,如果您直接刪除請求'123456789',則帶有此前綴的所有完整請求標識將被刪除。

============================================== ====================

如果您還沒有啓用請求2。0,按照文檔頁面上的代碼,看看通過進行API調用

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

響應格式這些方法如下:如何獲得用戶ID:

{ 
    "id": "[request_id]", 
    "application": { 
     "name": "[Application Name]", 
     "id": "[Application ID]" 
    }, 
    "to": { 
     "name": "[Recipient User Name]", 
     "id": "[Recipient User ID]" 
    }, 
    "from": { 
     "name": "[Sender User ID]", 
     "id": "[Sender User Name]" 
    }, 
    "message": "[Request Message]", 
    "created_time": "2011-09-12T23:08:47+0000" 
} 

您可以實現回調的api電話,並得到誰是接收器通過response.to.id

+0

謝謝hanon,但我如何在回調獲取用戶ID?是不是這樣? function requestCallback(response){ top.location.href =「REDIRECT_URL?req =」+ response.to; } – Oscar

+0

我更新了我的答案,看看如何獲​​得id數組。 如果你想跟蹤請求的數據 然後使用FB.api(「/ requestID」,回調)來獲取數據。 記住ID – Hanon

+0

的格式非常感謝,我得到了請求ID,但是如何知道這個請求ID是屬於哪個用戶ID?我需要用戶ID插入到我的數據庫,此外,我測試了你的代碼,它的工作,但一旦發送請求給我的朋友,我的朋友打開我的請求,它顯示白色的空白頁面,它顯示的鏈接是這樣的: http://apps.facebook.com/christmas_testing/?request_ids=132802000161969,我該如何解決這個問題? – Oscar

相關問題