Reputation: 343
I want to share URL with Google plus, after successful share I need response of success or failure.
I did it and also getting response but if i closed popup without share, then also onPlusDone
function executed.
So, I need something that will tell me success of share.
Below is my code:
<script type="text/javascript">
function onPlusDone(reponse) {
console.log(reponse);
var res = 'success';
$.ajax({
type:"POST",
dataType: "json",
data: {
res:res,
},
url: HOST+'user/success_share',
success:function(result){
}
})
}
function myCallback(jsonParam) {
console.log("URL: " + jsonParam.href + " state: " + jsonParam.state);
}
</script>
<g:plusone size="medium" href="http://myshareurl/" callback="myCallback" onendinteraction="onPlusDone"></g:plusone>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
Upvotes: 1
Views: 974
Reputation: 51
I have found a work around for this issue. Please find the below link to jsfiddle for the solution that i have come up with.
The solution is to intercept the onmessage window from google-plus share.
https://jsfiddle.net/g3hyx8p7/
<div style="width:40px !important" data-action="share"
class="g-plus" id="share-googleplus"></div>
gapi.plus.render('share-googleplus', {
action: "share",
href: 'http://stackoverflow.com/questions/6585722/use-custom-image-for-google1-button'
})
window.onmessage = function (mes)
{
var s = mes.data.replace("!_", "");
s = $.parseJSON(s);
if (s.s.indexOf("_g_restyleMe") != -1 && Object.keys(s.a[0]).length == 1 && s.a[0].hasOwnProperty("height")) {
alert("shared to goole")
}
}
Upvotes: 3
Reputation: 4474
There currently is not a way to detect that a user has shared content that is supported by the Google+ API.
Upvotes: 0