开发者

How to clear share link caching?

I tried to share a link for example http://apps.facebook.com/appname/ under "Update Status" on my profile page. After I modified the content of the application, it still display the caching. I tried to use the http://developers.facebook.com/tools/debug开发者_StackOverflow中文版 to clear the cache, but the result still the same. Any help would be greatly appreciated.


You can use the Object Debugger directly. Just paste your URL into there and hit Debug.

You can tell facebook to re-scrape the content using the "scrape=true" post parameter in a POST request to https://graph.facebook.com. More details in the Facebook docs.


  • Wait.
  • Try to lint that url again or tell anyone to do it for you (might have imedate effect)
  • Wait.


Try This:

$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);

Note that you need to pass the user agent, as this is require by Facebook Server to parse the request.


I had this problem, but it was with a specific post instead of the whole website. I was getting the cache in the debugger to show the right picture after updating my blog post, but when I went to post the link as a status, Facebook was still showing an old picture. I didn't want to wait a day to see if it would finally change, so I did what's outlined on this page:

https://webapps.stackexchange.com/questions/18468/adding-meta-tags-to-individual-blogger-posts

In other words, something like this:

<b:if cond='data:blog.url == "http://urlofyourpost.com"'>
  <meta content='http://urlofyourimage.png' property='og:image'/>
 </b:if>

Basically, you're going to hard code an if statement into your page's HTML to get it to change the meta content for whatever you've changed for that one post. It's a messy solution, but it works.


Above methods did not work for me. But, I have used javascript to clear the cache and get latest content in 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");
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜