简体   繁体   English

Facebook在共享对话框上显示我的登录页面,而不是当前页面标题和网址

[英]Facebook shows my login page on the share dialog instead of the current page title and url

I'm trying to integrate the Facebook share feature in my application but whenever I click on the share button , Facebook will pull up meta data from the head and instead of showing the current title and URL it returns my login page URL and login page title , I have tried this 我试图将Facebook共享功能集成到我的应用程序中,但是每当我单击共享按钮时,Facebook都会从头部提取元数据,而不是显示当前标题和URL,而是返回我的登录页面URL和登录页面标题,我已经试过了

Facebook share button is sharing my login page instead of current page URL, title, etc Facebook共享按钮正在共享我的登录页面,而不是当前页面的URL,标题等

But according to Facebook the Feed button was dereciated and replaced with the share button 但是根据Facebook的说法,“ 提要”按钮已弃用并由 “共享”按钮代替

The code below is included in every page of my app 下面的代码包含在我的应用程序的每个页面中

<meta property="og:title" content="<?php echo $title ?>"/>
<meta property="og:type" content="Type of content"/>
<meta property="og:url" content="<?php echo current_url() ; ?>"/>
<meta property="og:site_name" content="My site name"/>
<meta property="og:description" content="<?php echo $description ; ?>"/>

Ok, i think it's got to do something with the Facebook scraper. 好的,我认为必须使用Facebook抓取工具。 As mentioned in the docs here 由于在文档中提到的在这里

In some cases you may want to serve a different version of a page to our scraper (containing more Open Graph metadata) than you do to people who are viewing the page. 在某些情况下,您可能希望为我们的抓取工具提供不同版本的页面(包含更多的Open Graph元数据),而不是为查看页面的用户提供服务。 In this case you can target the browser agent used by the scraper: 在这种情况下,您可以定位刮板使用的浏览器代理:

"facebookexternalhit/1.1 (+ http://www.facebook.com/externalhit_uatext.php )" “ facebookexternalhit / 1.1(+ http://www.facebook.com/externalhit_uatext.php )”

So I think in the php file of your website you can put in a check for the scraper like this: 因此,我认为在您网站的php文件中,您可以像下面这样检查刮板:

    if (strstr( $_SERVER['HTTP_USER_AGENT'], 'facebookexternalhit') {
       // Show more open graph metadata here
    } else {
       // Your login page
    }

To make the scraper cache your data, use the debugger tool . 要使抓取工具缓存您的数据,请使用调试器工具

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM