How to clear share link caching?

核能气质少年 提交于 2019-12-09 02:14:06

问题


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 to clear the cache, but the result still the same. Any help would be greatly appreciated.


回答1:


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.




回答2:


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



回答3:


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.




回答4:


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.




回答5:


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");
    }
}


来源:https://stackoverflow.com/questions/7329105/how-to-clear-share-link-caching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!