2011-12-10 31 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。

这可能不是最好的方式 - 也许是,我不知道 - 但会做你要求的。