Get link from share

-1

I want to share a Facebook post by rescuing the link from the share, so you can share this link on Twitter. I'm taking a look at the Facebook documentation, I believe it allows it in some simple way.

    
asked by anonymous 09.04.2014 / 15:43

1 answer

3

Do you want to share the facebook link? Home Why not use the same link you used for facebook on other social networks? Home Explain it better, please. Home If you are using PHP, see a function to share on all social networks by interacting with the user click.

<?php
function social_networks ($title, $link) {
    $FB = 'http://www.facebook.com/sharer.php?u=' . rawurlencode($link) . '&t=' . rawurlencode($title);
    $google_plus = 'https://plus.google.com/share?url=' . rawurlencode($link) .'';

    $twitter = "window.open('http://twitter.com/home?status=". rawurlencode($title) ."','popups','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=700,height=500,top=100,left=100'); return false;";

    $facebook = "window.open('$FB','popups','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=700,height=500,top=100,left=100'); return false;";

    $gplus = "window.open('$google_plus','popups','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=700,height=500,top=100,left=100'); return false;";

    return (object) array( 'twitter' => $twitter, 'facebook' => $facebook, 'gplus' => $gplus );
}

$share = social_networks('Título', 'LINK');
?>
<!-- HTML -->
<a href="#" onclick="<?php echo $share->facebook ?>">Compartilhar no facebook</a>
<a href="#" onclick="<?php echo $share->twitter ?>">Compartilhar no Twitter</a>
<a href="#" onclick="<?php echo $share->gplus ?>">Compartilhar no Google plus</a>


And with javascript:

<!DOCTYPE html>
<html>
<head>
<script>
var social_networks = function(title, link) {
    var FB = 'http://www.facebook.com/sharer.php?u=' + encodeURIComponent(link) + '&t='+ encodeURIComponent(title);
    var google_plus = 'https://plus.google.com/share?url=' + encodeURIComponent(link);

    var twitter = "window.open('http://twitter.com/home?status="+encodeURIComponent(title)+"','popups','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=700,height=500,top=100,left=100'); return false;";

    var facebook = "window.open('"+ FB +"','popups','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=700,height=500,top=100,left=100'); return false;";

    var gplus = "window.open('"+ google_plus +"','popups','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=700,height=500,top=100,left=100'); return false;";

    return {'twitter':twitter, 'facebook':facebook, 'gplus':gplus};
};

var share = social_networks('Título', 'LINK');

// $(document).ready [...]
window.onload = function() {
    document.getElementById('facebook').setAttribute('onclick', share.facebook);
    document.getElementById('twitter').setAttribute('onclick', share.twitter);
    document.getElementById('gplus').setAttribute('onclick', share.gplus);
};
</script>
</head>

<body>
    <a href="#" id="facebook">Compartilhar no facebook</a>
    <a href="#" id="twitter">Compartilhar no Twitter</a>
    <a href="#" id="gplus">Compartilhar no Google plus</a>
</body>
</html>
    
09.04.2014 / 17:30