2011-12-10 20 views
2

我有一個FB應用程序,我可以使用Open Graph API成功發佈操作和對象到時間軸,代碼和紀事。Facebook圖形API,操作ID和哪個對象

我的問題是,有沒有辦法讓操作標識返回寫入mysql數據庫或從操作ID獲取實際的對象標題返回並將其寫入數據庫?

感謝您的幫助。

回答

1

你可以用AJAX來做到這一點。

例如:

function postNewAction() 
{ 
     passString = '&object=http://site.com/APP_NAMESPACE/object.php'; 

     FB.api('/me/APP_NAMESPACE:ACTION' + passString,'post', 
     function(response) { 
       if (!response || response.error) { 
        alert(response.error.message); 
       } 
       else { 
        storeInTable(response.id); 
       } 
      } 
    );  
} 

function storeInTable(id){ 
    if (window.XMLHttpRequest) 
    {// code for IE7+, Firefox, Chrome, Opera, Safari 
     xmlhttp=new XMLHttpRequest(); 
    } 
    else 
    {// code for IE6, IE5 
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    xmlhttp.onreadystatechange=function() 
    { 
     if (xmlhttp.readyState==4 && xmlhttp.status==200) 
     { 
      //Success!  
     } 
    } 
    xmlhttp.open("GET","storeInTable.php?id=" + id,true); 
    xmlhttp.send(); 
} 

然後您可以標識你的表存儲在課程storeInTable.php。

這可能不是最好的方式 - 也許是,我不知道 - 但會做你要求的。