1

我目前有一个网站,在我正在创建的社交网络小部件上包含 Google 分享按钮(以及 Facebook 和 Twitter)。我想做的是能够在 textarea 字段中输入一些文本,然后按下“发送”按钮,文本将共享到 Google+ 用户的墙上(我已经有 Facebook 和 Twitter 帖子工作)。现在我知道 Google+ 的共享按钮有一个名为“data-prefilltext”的字段,这是我尝试使用来自 textarea 的消息设置的字段。当我按下“发送”按钮时,我可以看到“数据预填充文本”字段值发生变化,但在弹出窗口中,我没有看到文本变化。下面是代码:

HTML:

<div id="googleplus-selector" title="App is what's new! Share it with your circles in Google+"
    class="social-networking-icons g-interactivepost"
    data-contenturl="http://plus.google.com/pages/"
    data-contentdeeplinkid="/pages"
    data-clientid="clientid.apps.googleusercontent.com"
    data-scope="https://www.googleapis.com/auth/youtube.readonly"
    data-cookiepolicy="single_host_origin"
    data-prefilltext="Share App with your circle of friends now!"
    data-calltoactionlabel="TRY_IT"
    data-calltoactionurl="http://plus.google.com/pages/"
    data-calltoactiondeeplinkid="/pages/create"
    data-href="http://mysiteurl">
        <div class="widget-mask"></div>
</div>

Javascript/jQuery:

var textElement = $('#social-message-text');
var text = textElement.val();
$('#google-plus-share-button').attr('data-prefilltext', text);

就像我说的,在检查 Firebug 或 Google 的开发者控制台中的元素时,我可以看到属性值的变化,但是当打开 Google Share 弹出窗口时,文本的变化不会反映出来。

任何帮助将不胜感激,因为我现在有点难过。提前感谢大家。

4

2 回答 2

1

I also have face the same problem.After long struggle i have found solution.I am sharing answer with u.

<html>
  <head>
    <title>Share Demo: Deferred execution with language code</title>
    <link rel="canonical" href="http://www.example.com" />
  </head>
  <body>
  <script>
  window.___gcfg = {
            lang: 'en-US',
            parsetags: 'explicit'
          };
  </script>
  <script type="text/javascript" src="http://apis.google.com/js/plusone.js"></script>
    <div id ="sharePost">Share</div>
 <script>
     (function() {
           var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
           po.src = 'http://apis.google.com/js/client:plusone.js';
           var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
         })();
     var options = {
                contenturl: 'http://www.google.com',
                contentdeeplinkid: '/pages',
                clientid: 'xxxxxxxxxxxxx.apps.googleusercontent.com',
                cookiepolicy: 'single_host_origin',
                prefilltext: 'Hai happy friday',
                calltoactionlabel: 'INVITE',
                calltoactionurl: 'http://www.google.com'
              };
              // Call the render method when appropriate within your app to display
              // the button.
              gapi.interactivepost.render('sharePost', options);

      </script>
  </body>
</html>

While you are getting response from ajax you have to call again google plus share js file after ajax response.

于 2014-10-10T06:44:59.630 回答
-1

You could render the button with javascript, with the next code example:

var options = {
                contenturl: 'https://dev.diesocialisten.at/google+/?v=5',
                clientid: 'YOUR CLIENT ID',
                cookiepolicy: 'single_host_origin',
                prefilltext: 'Developers, you should check this out!',
                calltoactionlabel: 'LEARN_MORE',
                calltoactionurl: 'https://dev.diesocialisten.at/google+/?v=5'
};
gapi.interactivepost.render('share-button', options); //button with the ID share-button
于 2014-09-30T02:24:09.617 回答