【问题标题】:Facebook xfbml Like Button not working correctlyFacebook xfbml Like 按钮无法正常工作
【发布时间】:2011-11-20 05:29:52
【问题描述】:

我的网站上有一个由 ajax 驱动的新闻部分。我正在尝试实现 Facebook Like 按钮的 xfbml 版本,但遇到了一些问题。

当第一次点击新闻项目上的“Like”时,没有任何 og 标签被拉入,所以你得到的只是一个 cmets 框。 奇怪的是,如果我随后查看另一个新闻项目并返回到第一个新闻项目,则like 按钮可以正常工作,并且所有 og 数据都被正确提取。好像是某种缓存问题?

在有机会输入评论之前,我还遇到了浮动弹出框在点击喜欢后消失的问题。它在那里只有几分之一秒。如果我不喜欢该新闻项目并重新喜欢它,浮动弹出框最终会保持不变,但可能需要多次尝试。

这是标题的示例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml" xml:lang="en-GB" lang="en-GB">
<head>
<meta property="og:title" content="She's in fashion"/>
<meta property="og:type" content="article"/>
<meta property="og:url" content="http://www.kirkleescollege.ac.uk/news/1103"/>
<meta property="og:image" content="http://www.kirkleescollege.ac.uk/photo/news/1103/full"/>
<meta property="og:site_name" content="Kirklees College"/>
<meta property="og:description" content="This year Rebekah Crowther will take the first steps towards her dream career in fashion retail thanks to a new course at Kirklees College."/>
<title>Kirklees College News - She's in fashion</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

这是正文代码,目前在测试服务器上,而不是实时服务器上。

<div id="fb-root"></div>
<script>
$(document).ajaxComplete(function(){
    try{
        FB.XFBML.parse(); 
    }catch(ex){
    }});

(function(d){
  var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
  js = d.createElement('script'); js.id = id; js.async = true;
  js.src = "//connect.facebook.net/en_US/all.js#appId=APPID&xfbml=1";
  d.getElementsByTagName('head')[0].appendChild(js);
}(document));



</script>

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#appId=APPID&xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-like" data-href="http://www.kirkleescollege.ac.uk/news/<?php echo $id; ?>" data-send="true" data-layout="button_count" data-width="450" data-show-faces="false"></div>

关于上述代码的一些事情需要提及,实时代码设置了我的应用 ID,但我不确定这是否是敏感信息,所以我在此处将其删除。我假设两个应用程序 ID 应该相同?
FB.XFBML.parse() 代码来自 Stackoverflow。它允许在 ajax 驱动的页面上加载点赞按钮。
我不明白为什么它是间歇性的。你会认为如果有问题,它仍然是一致的。

希望有人能提供帮助,因为这让我发疯了!

【问题讨论】:

  • 还值得一提的是,所有关于问题的内容都纯粹在我的网站端。当点击“发布到 Facebook”时,即使 og 内容没有出现在弹出窗口中,它通常也会显示在我的 Facebook 页面上。

标签: facebook facebook-like xfbml


【解决方案1】:

你必须在代码中添加appid

检查线路

js.src = "//connect.facebook.net/en_US/all.js#appId=APPID&xfbml=1";

您可以粘贴 自己的 appid

,而不是 APPID

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-17
    • 1970-01-01
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    • 2012-01-29
    • 1970-01-01
    相关资源
    最近更新 更多