Satish Z
Satish Z

Reputation: 27

how to integrate google+ share functionality with ruby on rails application?

I have simple erb template with following html code and javascript included.

<a class='share_on_gplus g-plus' data-social-action='share' data-medium='googleplus' data-content='q_name' href='https://plus.google.com/share?url=encodeURIComponent(URL).replace('%20','+') onclick="javascript:window.open(this.href,'','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=auto,width=600');return false';">Share with Google+ </a>

<script src="https://apis.google.com/js/client.js"></script>
<script type="text/javascript">
    function load() {
        gapi.client.setApiKey('XXXXXXXXXXXXXXXXXXx');

      }

    window.___gcfg = {
    lang: 'en-US',
    parsetags: 'onload'
    };

  (function() {
    var po = document.createElement('script'); 
    po.type = 'text/javascript'; 
    po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js?onload=load';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();

</script>

My Google +API service is already on. When I click on share button in google plus popup I got an error:

There was a problem saving your post. Please try again. I am not able to share on google+. How do I resolve this error?

Upvotes: 2

Views: 685

Answers (2)

Satish Z
Satish Z

Reputation: 27

Actually I need to mentioned the real domain name in url option and problem get solved. That's it!!!

Upvotes: 0

Prisoner
Prisoner

Reputation: 50701

If that is a cut-and-paste from your code, I think there are at least two problems:

1) Your href value opens with a single quote, closes with a double quote, and has several single quotes as part of it.

2) The Google sharing code and bot use the attributes that are attached to the share element to determine exactly what is being shared, including the href attribute. It looks like you're trying to pop up a window on your own and manipulate the share this way.

I would start by trying to do a more basic share button (as documented either here or here) and confirm that it can be used to share the page. If that does work, then you can start tailoring from there, but I don't think opening a new window will work the way you want.

Upvotes: 3

Related Questions