2014-09-29 59 views
0

我正在工作车辆跟踪网站,在这里我必须分享一些动态内容在谷歌加分享,这是作为预充文本。问题是我分享在谷歌加分享的内容,当我第一次点击谷歌加分享,内容获取后自动刷新一分钟一次通过ajax,预充文本内容得到更新,但我点击分享按钮在谷歌加分享窗口内容不会发布给任何人。谷歌加分享使用动态内容不工作

下面是示例代码

<html> 
    <head> 
    <title>Share Demo: Deferred execution with language code</title> 
    <link rel="canonical" href="http://www.example.com" /> 
    </head> 
    <body> 
    <script type="text/javascript" src="https://apis.google.com/js/client:plusone.js"></script> 
    <div id ="sharePost" action="share">Share</div> 
<script> 
function add(){ 
    var options = { 
     contenturl: 'https://plus.google.com/pages/', 
     contentdeeplinkid: '/pages', 
     clientid: 'xxx', 
     cookiepolicy: 'single_host_origin', 
     prefilltext: 'Hai happy friday'+Math.random(), 
     calltoactionlabel: 'CREATE', 
     calltoactionurl: 'http://plus.google.com/pages/create', 
     calltoactiondeeplinkid: '/pages/create' 
     }; 
     // Call the render method when appropriate within your app to display 
     // the button. 
     gapi.interactivepost.render('sharePost', options); 
} 

     setInterval(function(){ 
     add(); 
     },2000); 

     add(); 
     </script> 
    </body> 
</html> 

回答

0

我能使用Java脚本渲染,我们需要注意的method.The要点分享的互动讯息是,我们需要使用相同的URL contenturl和calltoactionurl。

<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: 'xxxxxxxxxxx.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>