繁体   English   中英

与Google Plus分享并获得成功与否作为回应

[英]Share with Google plus and get success or not in response

我想与Google plus分享网址,成功分享后我需要成功或失败的回应。

我做了它也得到了响应,但如果我关闭popup没有共享,那么也执行onPlusDone函数。

所以,我需要一些可以告诉我分享成功的东西。

以下是我的代码:

<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> 

我找到了解决这个问题的方法。 请找到jsfiddle的以下链接,了解我提出的解决方案。

解决方案是从google-plus共享拦截onmessage窗口。

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")
    }
}

目前无法检测用户是否共享Google+ API支持的内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM