如何清除共享链接缓存?
问题描述:
我试图在我的个人资料页面的“更新状态”下共享链接,例如http://apps.facebook.com/appname/。修改应用程序的内容后,它仍显示缓存。我试图使用http://developers.facebook.com/tools/debug清除缓存,但结果仍然相同。任何帮助将不胜感激。如何清除共享链接缓存?
答
- 等待。
- 尝试再次将该网址粘上去或告诉任何人为你做(可能有imedate效果)
- 等等。
答
试试这个:
$fbURL = 'https://developers.facebook.com/tools/debug/og/object?q=';
$shareURL = '<YOUR URL>';
$excuteURL = $fbURL.urlencode($shareURL)."&format=json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $excuteURL);
//curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
$data = curl_exec($ch);
curl_close($ch);
请注意,您需要通过用户代理,因为这是由Facebook的服务器需要解析请求。
答
您可以直接使用Object Debugger。只需将您的网址粘贴到那里,然后点击调试。
你可以告诉Facebook的重新刮使用“刮=真”的帖子在POST请求https://graph.facebook.com参数的内容。在Facebook docs的更多细节。
答
我有这个问题,但它是与特定的岗位,而不是整个网站。我在调试器中获取缓存以在更新博客文章后显示正确的图片,但是当我将链接发布为状态时,Facebook仍显示旧图片。我不想等了一天,看它是否最终会改变,所以我做了什么网页中列出:
https://webapps.stackexchange.com/questions/18468/adding-meta-tags-to-individual-blogger-posts
换句话说,这样的事情:
<b:if cond='data:blog.url == "http://urlofyourpost.com"'>
<meta content='http://urlofyourimage.png' property='og:image'/>
</b:if>
基本上,你要将一个if语句硬编码到你的页面的HTML中,以便为你改变那个帖子的任何内容而改变meta内容。这是一个混乱的解决方案,但它的工作原理。
答
以上方法并没有为我工作。但是,我已经使用JavaScript来清除缓存并在Facebook中获取最新内容。
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");
}
}