2012-11-02 53 views
3

我看過這個articleFacebook與數據對話框

所以,我試了一下,我把一個數字放在data屬性中。

FB.ui({ 
    method: 'apprequests', 
    message: 'Come join me and play at MyWebSite!', 
    data: '12345', 
    redirect_uri: 'myWebSite' 
}); 

我得到的request_ids,但如何獲取數據部分(12345號)?

回答

5

在服務器端,你可以這樣做:(使用PHP這裏)

$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']; //$req_data will be '12345' as per your request data set. 
     // after getting the data, you may like to delete the request. 
      $full_request_id = $request_id."_".$fbid; //$fbid is current user facebook id 
      $facebook->api("$full_request_id","DELETE"); 
    } 
+1

謝謝你Smita,對不起,我剛剛讀了這個,所以我要去應用它。非常感謝你。 – goofy

+1

非常感謝,希望大家能看到這個。因爲它工作。謝謝你的啓發 – goofy

1

你也試過Facebook的文檔嗎?

https://developers.facebook.com/docs/requests/有更多文檔;如果data參數是在調用請求對話框添加,相同的值也應該有通過API請求請求詳細信息時(即/REQUEST_ID通話)

+0

hmmmm,這更是有意義的我,雖然我只看到它的幾個部分。當我讀完它時我會回覆你 – goofy

+0

所以我讀過它。基本上我需要的是幾乎類似於應用程序的用戶請求,但不幸的是它只適用於畫布應用程序。雖然我的網站是。 – goofy

+0

用戶對用戶和應用程序用戶請求僅適用於畫布應用程序和移動應用程序 – Igy

0

詳情參見 Facebook的開發者網站的文檔http://developers.facebook.com/docs/reference/dialogs/requests/

注:

data:您可以通過跟蹤可選的,額外的數據。這將作爲創建的請求對象的一部分進行存儲。最大長度爲255個字符。

+0

我讀過它,它仍然讓我困惑。我的意思是,要獲得request_ids。我使用php $ _GET方法。但它給了我一個數字,我假設它是一個request_id。但是我沒有得到數據部分。或者它可能已經在request_ids中,我只是不知道如何提取它 – goofy