I used to have share buttons in a dynamically created page that shared specific content from the page:
<a class="share" onclick="window.open('http://www.facebook.com/sharer.php?s=100&p[title]=TITLE&p[summary]=SUMMARY&p[url]=http://www.facebook.com&&p[images][0]=imageurl', 'newwindow', 'width=555, height=315'); return false;"></a>
This resulted in a share window with the content that was specified in the parameters inside the above code (TITLE, SUMMARY, IMAGEURL, URL, etc). It seems, however, that recently Facebook deprecated this code and now what's happening is that when you try to share, you see my specified parameters but once you post them on Facebook different content shows up!
Instead of seeing my specified parameters, it seems like Facebook crawls the page that's specified in the URL and looks for the information inside the meta tags on that page. This means that all my share buttons on the page are now posting the same meta tag.
Anyone know how I can fix this or basically share custom content?
You can create a file on your server that serves a valid HTML file with the correct meta tags.
shared.php?title=Hello&description=FooBar&image=URL&link=LINKURL
<html><head>
<meta property="og:title" value="<?php echo $_GET['title'] ?>" />
<meta property="og:description" value="<?php echo $_GET['description'] ?>" />
<meta property="og:image" value="<?php echo $_GET['image'] ?>" ?>
<script type='text/javascript'>
setTimeout(function() {
document.location = "<?php echo $_GET['link'] ?>"; }, 500
);
</script>
</head></html>
Now just pass this file with the sharer.php, passing all your parameters into this, like so:
<div
class="fb-share-button"
data-href="http://YOURSERVER.com/shared.php?title=Hello&description=FooBar&image=URL&link=LINKURL"
data-type="button_count">
</div>
Or with your original JS code:
<a class='share' onclick="window.open('https://www.facebook.com/sharer/sharer.php?app_id=YOURAPPID&sdk=joey&u=http%3A%2F%2Fyourserver.com%2Fshared.php%3Ftitle%3DHello%26description%3DFooBar%26image%3DURL%26link%3DLINKURL&display=popup', 'newwindow', 'width=555, height=315'); return false;"></a>
When facebook comes crawling your URL, since it passes along the same URL parameters, the same meta tags will be created every time.
A slight delay in the Javascript URL redirect is required to avoid Facebook crawler following through the redirect to the final destination; users clicking on the link in Facebook feed will still get redirected to the final location.
I was able to find an answer to my solution! I discovered that Facebook released updates in October 2013 to the Feed Dialogue methods the broke the old share codes. Here is an article with recommendations for updating sharing code to the Feed Dialogue method to comply with the October 2013 Breaking Changes: https://developers.facebook.com/docs/reference/dialogs/feed/
I just added extra parameters to the redirection – TITLE & IMAGE (you can see a list of all available parameters at the bottom of that page) and was able to match the look & feel to the old share message. Also had to specify an app ID. Just tested everything and it seems to work again.
https://www.facebook.com/dialog/feed?app_id=145634995501895&display=popup&caption=SUMMARY&link=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fdialogs%2F&redirect_uri=https://developers.facebook.com/tools/explorer&name=TITLE