2014-02-18 40 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"); 
    } 
}