Question

I want the user to be able to share(post) some data to facebook/linkedin from my page. There was a facebook sharer link but it is supposed to be deprecated now? I tried this but it doesn't work entirely. There is a share button but I need just a link from html without any additional mess.

People seem to like sharrre but I think there should be an easier solution.

I noticed there are two different aspects when trying to share data:

  • pre create text to put into share textbox (this works for twitter with Sharrre for instance, but not for Fb/LinkedIn… )
  • use url to put into sharer and the sharer automatically detects properties such as title,image,description (text stays blank and it's up to user to write something)

What is the current best and fastest way to share some info from your page to facebook and/or linkedin? (without using generated share buttons)

##### EDIT: I figured it out for LinkedIn. You can just use

https://www.linkedin.com/cws/share?url=YOUR_URL?YOUR_PARAMETER=PARAM_VALUE

and with this you are able to show your param onward with php $_GET for instance and put it in

<meta property="og:description" content="This is my param <?php echo $_GET['YOUR_PARAMETER'] ?>"

This way you can show your customised information with sharing.

For Facebook there is an issue with passing params-they do not get read. Link is formed correctly but when redirected to Facebook sharer the url gets encoded differently. Any ideas?

http://www.facebook.com/sharer.php?u=YOUR_URL?YOUR_PARAMETER=PARAM_VALUE
Was it helpful?

Solution

I figured it out: If you want to pass your custom data to share with Facebook and LinkedIn this is what you need:

  • create your own server (in my case php) with custom data that looks something like this:

    <?php
    
    if(isset($_GET['YOUR_PARAMETER']))
        $par = $_GET['YOUR_PARAMETER'];
    
    ?>
    <meta charset="utf-8">
    <title>SITE TITLE</title>
    <meta property="og:title" content="SITE TITLE" />
    <meta property="og:type" content="website" />
    <meta property="og:url" content="YOUR_URL?YOUR_PARAMETER=<?php echo $par ?>" />
    <meta property="og:image" content="YOUR_IMG_URL_CAN_USE_PARAMETERS_ALSO" />
    <meta property="og:description" content="You can use your parameter that will be shown as description when sharing to facebook like this: This is my parameter! <?php if($par) echo $par; ?>!" />
    

(put all this in head tag of course; you can leave body empty… )

  • use this link in your html when you want to share to Fb/Linkedin (this example is with AngularJS, but you could pass the variable for instance in php with echo as well)

    <a ng-href="http://www.facebook.com/sharer.php?u=YOUR_URL?YOUR_PARAM={{PARAM_VALUE}}" target="_blank">
            <div class="text">Share via Facebook</div>
    </a>
    

So to sum up:

Use

http://www.facebook.com/sharer.php?u=YOUR_URL?YOUR_PARAM=PARAM_VALUE

to share to Facebook (this sharer is supposed to be deprecated but it works)

Use

https://www.linkedin.com/cws/share?url=YOUR_URL?YOUR_PARAMETER=PARAM_VALUE

to share to Linkedin.

But beware: Facebook takes parameters only from

<meta property="og:url"

where LinkedIn takes them from the url that your customised server resides on.

You can use Facebook debugger tool to see what your customised server returns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top