简体   繁体   中英

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 share button is sharing my login page instead of current page URL, title, etc

But according to Facebook the Feed button was dereciated and replaced with the share button

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. 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. In this case you can target the browser agent used by the scraper:

"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:

    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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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