carrot / share-button

:warning: :warning: Currently Unmaintained :warning: :warning: - fast, beautiful, and painless social shares:
http://sharebutton.co/
Other
2.95k stars 381 forks source link

Callback after successfully Shared #167

Open ArchTaqi opened 9 years ago

ArchTaqi commented 9 years ago

I want to get callback if the page has been successfully been shared or not. I have used before and after but it only functions when the sharing windows opens, not when exactly the contents has been shared.

 return FB.ui({
        method: 'feed',
        name: this.config.networks.facebook.title,
        link: this.config.networks.facebook.url,
        picture: this.config.networks.facebook.image,
        caption: this.config.networks.facebook.caption,
        description: this.config.networks.facebook.description
      },
      function(response) {
      if (response && response.post_id) {
      console.log('Post was published.');
      } else {
      console.log('Post was not published.');
      }
}

Managed to get callback for facebook, but unable for twitter and others

jescalan commented 9 years ago

Yeah this depends on whether each individual network provides a callback. As we add more networks, this will become difficult to make consistent as a feature. If you could look into the support other networks have for a post-share callback and post it here, that would help a ton!

ArchTaqi commented 9 years ago

As far as I know Facebook, Twitter and Linkedin provides callback if you use their JS APIs. As you have use FB feed API so it was easy for me to put a callback function for facebook but for others you have use their share url. If you use their api instead of Share url it would become easier to putt callback functions for them also.

ArchTaqi commented 9 years ago

From this Article http://projs.hackhat.com/how-to-make-a-custom-share-tweet-button-and-know-when-the-user-clicked/

I used this as

var tweetUrlBuilder = function(o){
    return [
        'https://twitter.com/intent/tweet?tw_p=tweetbutton',
        '&url=', encodeURI(o.url),
        '&via=', o.via,
        '&text=', o.text
    ].join('');
};

$('.entypo-twitter').on('click', function(){
    var url = tweetUrlBuilder({
        url : 'http://bit.ly/OChT65',
        via : 'ProJavaScript',
        text: 'How to make a custom share tweet button and know when the user tweeted'
    });
    window.open(url, 'Tweet', 'height=500,width=700');
})

// Called by the Twitter, many times during it's
// life-cycle. We only want to know when the user
// has tweeted, so the following filters are required.
var callback = function(e){
    if(e && e.data){
        var data;
        try{
            data = JSON.parse(e.data);
        }catch(e){
            // Don't care.
        }
        if(data && data.params && data.params.indexOf('tweet') > -1){
            alert('Thanks for the tweet!');
        }
    }
};

window.addEventListener ? window.addEventListener("message", callback, !1) : window.attachEvent("onmessage", callback)

Now, need to call this function in your Share.prototype.network_twitter

hhsnopek commented 9 years ago

Hey, @TaqiOfficial - we've been looking into this. If you find anymore like the twitter one, let us know! Otherwise in v1.0.0 we're going to have the option to load a platforms JS lib for this and other functionality

ArchTaqi commented 9 years ago

I am also working on it, As I have no prior exp. contributing to git repo via pull, merge etc. so i will share my code here, else I will contribute to this repo.

dingzhanjun commented 8 years ago

Hi, I tried this, it does not work, I also tried the original stuff on JSFIlldel, not either

gomalpradeep commented 7 years ago

HI @taqiofficial the above script does not work

jasan-s commented 7 years ago

any update on this? I wanted to get a successful callback , so I can offer a user discount code

MBK8303 commented 6 years ago

how we can get response after sharing content from Facebook in asp.net....:) that response is null or not. Please send me suggestions