google+ share and onendinteraction - no confirm

淺唱寂寞╮ 提交于 2019-12-05 11:10:21

So this appears to be a bug with the current implementation of the google+ share button:

https://code.google.com/p/google-plus-platform/issues/detail?id=396

The (hideous) workaround I've used for now is to look for 2 hover events for the onendinteraction. If the events come in quick succession (less than 1 second), then it's likely they've shared the item.

Quite late on this one so it might not be relevant but according to Google Developer page for their web platform, it seems you can tap into the current users activities list using a javascript code similar to -

var request = gapi.client.plus.activities.list({
  'userId' : 'me',
  'collection' : 'public'
});

request.execute(function(resp) {
  var numItems = resp.items.length;
  for (var i = 0; i < numItems; i++) {
    console.log('ID: ' + resp.items[i].id + ' Content: ' +
      resp.items[i].object.content);
  }
});

The online tool to generate and test the query end point is there on the Developer Page

Generate and append a custom query string to the end of the link your user is sharing, the JSON returned from the end point can be parsed to check if that particular link has been shared on the users activity stream. The JSON returned looks like this -

{
 "items": [
  {
   "title": "",
   "published": "2015-06-12T16:39:11.176Z",
   "url": "https://plus.google.com/+UserID/posts/PostID",
   "object": {
    "content": "",
    "attachments": [
     {
      "objectType": "article",
      "url": "http://www.example.com"
     }
    ]
   }
  }
 ]
}

If the link with the custom query is there in the attachments section of one of the returned items,Voila! Its been shared.

craig

A Possible solution to this would be the following as a work around.

  1. Make the users open a new window which contains ONLY the Share Button Code passing the url to be shared
  2. Set a variable to 0 on window load
  3. In your function redirectGooglePlus update the variable to 1 when data-onendinteraction is called
  4. Check the window for close and verify the variable was set

    function closeWin(){
    
     if(x==0){
        //not shared before leaving code;
     }else{
        //shared before window closed;
     }
    }    
    body onbeforeunload="closeWin()" 
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!