2014-02-18 39 views
1

我正在使用Wordpress并且正在发生一件事情。我之前已经分享了一个链接,它在图片改变后有一个不同的图片。facebook在分享时采用了与之前相同的图片。让我告诉你什么程序我都试过如何在共享图像和文本时清除Facebook缓存

头节

<meta property="og:title" content="<?php echo $blogArray['post_heading'];?>" /> 
<meta property="og:type" content="article" /> 
<meta property="og:image" content="<?php echo $blogArray['image_url'];?>" /> 
<meta property="og:url" content="<?php echo site_url().'?page_id=3205&id='.base64_encode($blogArray['ID']);?>" /> 
<meta property="og:description" content="<?php echo $blogArray['post_sort_details'];?>" /> 

和HTML

http://www.facebook.com/sharer.php?s=100;&amp;p[title]=<?php echo $blogArray['post_heading'];?>&amp;p[summary]=<?php echo $blogArray['post_sort_details'];?>&amp;p[url]=<?php echo 'http://'.str_replace('http://','',str_replace('www.','',site_url()));?>/?p=<?php echo $blogArray['share_post_id'];?>&amp;p[images][0]=<?php echo $blogArray['image_url'];?>" target="_blank"><img src="<?php bloginfo('template_url');?>/images/fb_static.png" border="0" class="fb" title="Share via Facebook" width="24" height="24" /></a> 

但是,当我从同一网站上的测试文件夹尝试它是未来精绝。

我附上截图与此。

What I want to share 我想分享什么

What is getting shared from the Main Site 什么正从主站点

What is getting shared from the Beta site and the right one 什么正从测试网站和右共享一个

我见过共享一旦一个帖子在Facebook上分享。 Facebook将图片和文本保存到缓存中,甚至在更改图片和文本时,Facebook分享会保留以前的身份。这是我面临的主要问题,并希望通过在共享之后使用当前文本和图像重新加载Facebook缓存来解决。

+3

看看http://stackoverflow.com/questions/10285522/how-to-clear-facebooks-image-cache –

回答

2

林果皞是对的。您可以通过Facebook的调试器工具刷新缓存。只需将URL分配到您正在共享的调试器工具上即可。

您也可以使用网站上的这个脚本,你不需要去调试工具和手动刷新页面。下面的代码自动刷新Facebook页面。

$.post(
    'https://graph.facebook.com', 
    { 
     id: '[PAGE_URL]', 
     scrape: true 
    }, 
    function(response){ 
     console.log(response); 
    } 
); 
0

我拉着我的头发试图解决这个问题。几个小时和几个小时的排除故障无济于事。在与我们的一位程序员谈论一个无关的话题之后,我想到了一些可以尝试的方法。

出乎我的意料,它的工作!

这是问题,我为它的解决方案背后的原因:

当你起草的WordPress是基于你的文章的标题的链接(除非你手动修改)后。我的文章标题包含特殊字符,但自动生成的链接不显示这些特殊字符,只能用连字符替换空格。应该没事吧?错误!在WordPress平台中嵌入元数据和代码的地方就是那些特殊字符,它们混淆了Facebook从链接文章中获取信息的方式。这是一个问题,因为某些特殊字符使超链接无效。

例如:

文章标题:R eloaded]在WordPress “永久” 栏中显示 自动生成的超链接:http://www.example.com/reloaded 实际WordPress的自动生成的超链接:http://www.example.com/r[eloaded]

这些括号将无效链接和Facebook将无法从它拉任何信息(即图片)。

解决方案:

(1)简单,手动更改WordPress的超链接地址的东西,不包括任何特殊字符(这不会改变你的文章的标题)。

(2)单击“更新”改变的帖子,包括新的超链接。

(3)在WordPress的窗口中单击 “从缓存中清除”

(4)刷新你的Facebook浏览器窗口

(5)粘贴到新的超链接为你的文章

(6)享受你的Facebook发布了预览图像和信息

旁注:不要拉你的头发,在Facebook上,这是不值得的。 =)

0

我尝试了很多以编程方式清除缓存。我们可以使用facebook调试器手动清除缓存。但是,当我们在诸如http://myurl.com/?fbrefresh=xyz之类的网址之后保留任何参数时,它就起作用了。但是,手动清除缓存不是简单的事情,我们不能每次都做。

最后,它与JavaScript工作。当我把像上面提到的url之后的参数放在后面时,这个工作起作用了。

if(window.location.search.indexOf("facebook_refresh") >= 0) { 
    //Feature check browsers for support 
    if(document.addEventListener && window.XMLHttpRequest && document.querySelector) { 
     //DOM is ready 
     document.addEventListener("DOMContentLoaded", function() { 
      var httpRequest = new XMLHttpRequest(); 
      httpRequest.open("POST", "https://graph.facebook.com", true); 

      httpRequest.onreadystatechange = function() { 
       if (httpRequest.readyState == 4) { 
        console.log("httpRequest.responseText", httpRequest.responseText); 
       } 
      }; 

      //Default URL to send to Facebook 
      var url = window.location; 

      //og:url element 
      var og_url = document.querySelector("meta[property='og:url']"); 

      //Check if og:url element is present on page 
      if(og_url != null) { 
       //Get the content attribute value of og:url 
       var og_url_value = og_url.getAttribute("content"); 

       //If og:url content attribute isn't empty 
       if(og_url_value != "") { 
        url = og_url_value; 
       } else { 
        console.warn('<meta property="og:url" content=""> is empty. Falling back to window.location'); 
       }    
      } else { 
       console.warn('<meta property="og:url" content=""> is missing. Falling back to window.location'); 
      } 

      //Send AJAX 
      httpRequest.send("scrape=true&id=" + encodeURIComponent(url)); 
     }); 
    } else { 
     console.warn("Your browser doesn't support one of the following: document.addEventListener && window.XMLHttpRequest && document.querySelector"); 
    } 
}