Grab link from the share

Asked

Viewed 769 times

-1

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

  • Are you using the Javascript SDK from Facebook? Every post you do with it will return the post ID. With this ID you can mount the final URL or make a request in the API and get all the data. https://developers.facebook.com/docs/sharing/reference/feed-dialog and http://answall.com/a/12692/2554

1 answer

3

You want to share the facebook link?
Why not use the same link you used for facebook on other social networks?
Explain it better, please.
If you’re using PHP, see a share function on all social networks 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.