Google plus share button callback (when share is s

2019-04-09 17:37发布

问题:

is there a way to get the callback for a succeful share with this code ? (it's for sharing a link on google plus)

<a href="https://plus.google.com/share?url={URL}" onclick="javascript:window.open(this.href,
  '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><img
  src="https://www.gstatic.com/images/icons/gplus-64.png" alt="Share on Google+"/></a>

thank you

回答1:

https://developers.google.com/+/web/share/

onendinteraction


function(jsonParam)


If specified, this function is called when the interaction bubble disappears. You can use this callback function to modify your page, such as resuming a video, when the bubble closes.

This function accepts a single parameter, which is identical in structure to the parameter passed to onstartinteraction.



回答2:

aybe too little to late, but I had a solution working to this problem in my code a while back.

Completely undocumented as far as I know, but somewhere on a chinese forum I found the 'data-onshare' attribute that you can add to your share button, and set it to a method that gets a result back. As I recall, this might get called multiple times (?), so you have to check for the 'shared' result to make sure it was successful. It was working last year when I used it. Not documented, so not sure if it will be supported.

Note that the 'data-callback' is called when the user logs in to google I think - not when the share occurs (kind of misleading to me).

<script>
 function shareState(result)
        {
            console.log('share state ' + JSON.stringify(result));
            if (result['action'] === 'shared')
            {
                // success!
                console.log( result['post_id'] );
            }
        }
</script>

HTML share button:

<button 
data-onshare="shareState"
id='postBitTag'
    class="g-interactivepost btn btn-large btn-primary"
    data-contenturl="/pageOfInterest"
    data-clientid="<?php echo GoogleApi::$client_id; ?>"
    data-cookiepolicy="single_host_origin"
    data-prefilltext="I created a new HelpTile!"
    data-calltoactionlabel="DISCOVER"
    data-calltoactionurl="<?php echo $baseDomain; ?>/ht/id/X"
    data-callback='loggedIn'
>Create BitTag 
</button>