我正在工作车辆跟踪网站,在这里我必须在谷歌加分享一些动态内容,这是预填充文本。问题是我在谷歌加分享的内容是共享的,当我第一次点击google plus分享时,内容通过ajax自动刷新一分钟后,预填充文本内容会更新,但我点击google plus分享按钮窗口内容未发布给任何人。
以下是示例代码
<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 :(得分:0)
我可以使用java脚本渲染方法共享交互式帖子。我们需要注意的要点是,我们需要为contenturl和calltoactionurl使用相同的URL。
<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>