【问题标题】:How to clear share link caching?如何清除共享链接缓存?
【发布时间】:2011-11-11 20:20:43
【问题描述】:

我尝试在我的个人资料页面的“更新状态”下分享一个链接,例如 http://apps.facebook.com/appname/。在我修改应用程序的内容后,它仍然显示缓存。我尝试使用http://developers.facebook.com/tools/debug 清除缓存,但结果还是一样。任何帮助将不胜感激。

【问题讨论】:

    标签: facebook hyperlink share


    【解决方案1】:

    您可以直接使用Object Debugger。只需将您的 URL 粘贴到那里并点击调试。

    您可以告诉 facebook 在对https://graph.facebook.com 的 POST 请求中使用“scrape=true”发布参数重新抓取内容。更多详情请关注Facebook docs

    【讨论】:

      【解决方案2】:
      • 等等。
      • 尝试再次检查该网址或告诉任何人为您执行此操作(可能会立即生效)
      • 等等。

      【讨论】:

        【解决方案3】:

        试试这个:

        $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 服务器解析请求所必需的。

        【讨论】:

          【解决方案4】:

          我遇到了这个问题,但它是针对特定帖子而不是整个网站。更新博客文章后,我在调试器中获取缓存以显示正确的图片,但是当我将链接作为状态发布时,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>
          

          基本上,您将在页面的 HTML 中硬编码一个 if 语句,以使其更改您为该帖子所做的任何更改的元内容。这是一个混乱的解决方案,但它有效。

          【讨论】:

            【解决方案5】:

            以上方法对我不起作用。但是,我使用 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");
                }
            }
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2017-05-22
              • 1970-01-01
              • 2015-10-05
              相关资源
              最近更新 更多