当用户通过Facebook共享按钮共享页面时,我正在尝试检测爬行; 但是,在查看实时日志时,单击按钮时似乎没有任何东西击中我的控制器。
我们的想法是检测user-agent并呈现与用户实际访问网站时共享的不同内容。
在我的控制器中,我有以下内容:
def show Rails::logger.debug "********************************" Rails::logger.debug "#{self.class.name} - params: #{params.inspect}" Rails::logger.debug "#{self.class.name} - request.headers['HTTP_USER_AGENT']: #{request.headers['HTTP_USER_AGENT'].inspect}" Rails::logger.debug "********************************" render "pages/fb_test", layout: false end分享按钮
.fb-share-button{:"data-href" => "http://myapp.herokuapp.com/pages/1", :"data-layout" => "button", :"data-size" => "small", :"data-mobile-iframe" => false} %a.fb-xfbml-parse-ignore{target: "_blank", href: "https://www.facebook.com/sharer/sharer.php?u=http://myapp.herokuapp.com/pages/1"} Share我假设当我点击分享按钮时,Facebook会点击提供的URL,抓取页面并返回相关内容。 但是,当我使用heroku logs --tail时,当我点击分享按钮时,我根本没有看到任何活动,但内容仍然在Facebook共享弹出窗口中正确呈现。
我是否需要在Rack级别检测到这一点?
I'm trying to detect a crawl when a user shares a page via the Facebook share button; However, when looking at the live logs, nothing appears to be hitting my controller when I click on the button.
The idea was to detect the user-agent and render different content to be shared vs when a user actually visits the site.
In my controller I have the following:
def show Rails::logger.debug "********************************" Rails::logger.debug "#{self.class.name} - params: #{params.inspect}" Rails::logger.debug "#{self.class.name} - request.headers['HTTP_USER_AGENT']: #{request.headers['HTTP_USER_AGENT'].inspect}" Rails::logger.debug "********************************" render "pages/fb_test", layout: false endshare button
.fb-share-button{:"data-href" => "http://myapp.herokuapp.com/pages/1", :"data-layout" => "button", :"data-size" => "small", :"data-mobile-iframe" => false} %a.fb-xfbml-parse-ignore{target: "_blank", href: "https://www.facebook.com/sharer/sharer.php?u=http://myapp.herokuapp.com/pages/1"} ShareI would assume that when I click on the share button, Facebook would hit the URL provided, crawl the page and return the relevant content. However, when using heroku logs --tail I'm not seeing any activity at all when I click on the share button, and yet the content is still rendered properly in the Facebook share popup.
Do I need to detect this at the Rack level or something?
最满意答案
Facebook缓存您的网站。 您需要访问https://developers.facebook.com/tools/debug/sharing/ ,输入您网站的URL并单击“再次抓取”以刷新Facebook的缓存。
Facebook caches your website. You'll need to go to https://developers.facebook.com/tools/debug/sharing/, enter the URL of your website and click on "Scrape again" to refresh Facebook's cache.
更多推荐
发布评论