【问题标题】:Liking a Photo using FB API and JQuery使用 FB API 和 JQuery 为照片点赞
【发布时间】:2012-02-13 20:45:45
【问题描述】:

我在尝试使用 JQuery 点赞照片时遇到问题。我尝试过 .post、.ajax,现在使用 FB.api 帖子。当我运行脚本时,我什至没有收到错误消息。这就是单击“喜欢”按钮时我所拥有的功能:

function like(postId) {
    FB.api('/'+postId+'/likes', 'post', function(result) {
        if (!result) {
            alert('Error: No Response');
        } else if (result.error) {
            alert('Error: '+result.error.message+'');
        } else {
            if (result==true) {
                $('#likeButton-'+postId).hide();
                $('#unlikeButton-'+postId).show();
            }
        }
    });
}

任何建议都会很有帮助,因为我已经搜索了几个小时的 FB api 文档!!

【问题讨论】:

    标签: jquery facebook facebook-like photo


    【解决方案1】:

    我想通了,我必须编写要在解析时而不是运行时定义的函数(因为问题已格式化)

    like = function(postId) {
        FB.api('/'+postId+'/likes', 'post', function(result) {
            if (!result) {
                alert('Error: No Response');
            } else if (result.error) {
                alert('Error: '+result.error.message+'');
            } else {
                if (result==true) {
                    $('#likeButton-'+postId).hide();
                    $('#unlikeButton-'+postId).show();
                }
            }
        });
    }
    

    【讨论】:

      【解决方案2】:

      试试这个:

      function like(postId) {
          FB.api('/'+postId+'/likes', 'post', function(result) {
              console.dir(results);
          });
      }
      

      并检查您的浏览器控制台以获取完整的对象,并让我们知道您看到了什么。

      还可以使用浏览器的网络嗅探器来查看 API 调用的响应内容。

      【讨论】:

      • 它说找不到变量:like
      • 我的点赞按钮内容为:
      • ps。不应该有);在 FB.api 调用结束时?
      • 我想通了,我不得不写这样的函数:like = function(postId) {....
      • 抱歉,在 javascript 中 function like(postId) {like = function(postId) { 相同。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多