如何使用javascript创建一个按钮来删除一个动作(Facebook Open Graph)

时间:2012-04-06 05:47:39

标签: facebook facebook-graph-api facebook-opengraph

教程代码是:

  <script type="text/javascript">
  function postCook()
  {
      FB.api(
        '/me/[YOUR_APP_NAMESPACE]:cook?recipe=http://fbwerks.com:8000/zhen/cookie.html',
        'post',
        function(response) {
           if (!response || response.error) {
              alert('Error occured');
           } else {
              alert('Cook was successful! Action ID: ' + response.id);
           }
        });
  }
  </script>

我需要以相同的方式创建一个按钮,但要删除时间轴的选项。 谢谢。

1 个答案:

答案 0 :(得分:1)

请注意,只有拥有要删除的项目的操作ID时,才能执行此操作。因此,如果按如下所示设置按钮,则可以使用:

//Button code
<button onclick="deleteCook(ActionID)">Delete Cook </button>

 <script type="text/javascript">   
function deleteCook(ActionID) {



            FB.api(ActionID, 'delete', function(response) {
              if (!response || response.error) {
                alert('Error occured');

              } else {
                 alert('Cook action was deleted');
                          }
            });

                                               });
           }
</script>