要在您的网站上添加Google的plusone按钮,请插入以下脚本标记(用于显式加载).
<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
{"parsetags": "explicit"}
</script>
Run Code Online (Sandbox Code Playgroud)
它在HTML中看起来非常简单.但是我不想使用JS文件插入脚本.所以我使用以下代码:
var e = document.createElement('script');
e.src = "https://apis.google.com/js/plusone.js";
e.id = "googplusonescript";
e.innerHTML = '{"parsetags": "explicit"}';
document.getElementsByTagName("head")[0].appendChild(e);
Run Code Online (Sandbox Code Playgroud)
它在IE以外的所有浏览器中都非常棒,因为IE不允许我们编写脚本标签的innerHTML.任何人都可以做任何事吗?(我在页面中插入了jquery.所以也可以使用jquery.)
我一直在互联网上搜索如何获得programaticaly谷歌加一键计数.最后我发现这篇文章 这里是arcticle中提到的Php脚本.
<?php
$url = "http://www.tomanthony.co.uk/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
$curl_results = curl_exec ($ch);
curl_close ($ch);
$parsed_results = json_decode($curl_results, true);
echo $parsed_results[0]['result']['metadata']['globalCounts']['count'];
?>
Run Code Online (Sandbox Code Playgroud)
我尝试了一切,我已经坐了3个小时,但可以让它工作.但它似乎对他非常好.它是完全直接和简单的脚本.
我甚至使用firebug来检查请求.我尝试用找到的一个替换post数据值.
[{"method":"pos.plusones.get","id":"pos.plusones.get","params":{"cdx":"cb4","id":"http://www.tomanthony.co.uk/google_plus_one_api_example.php","source":"widget","container":"http://www.tomanthony.co.uk/google_plus_one_api_example.php","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"pos.plusones.get","apiVersion":"v1"}]
Run Code Online (Sandbox Code Playgroud)
我不知道我哪里错了.它只是一个简单的代码.
我正在建立一个基于滑块的图片库,并通过javascript加载新图片,并且需要通过javascript设置Google +1按钮的网址,因此可以在每张图片上设置+1.
我还需要根据每个图像重新加载+1按钮(该URL将包含一个包含图像ID的查询字符串参数,以使其唯一).这可能吗?
我正在尝试在页面上加载google + 1按钮,目标是通过ajax将按钮标记插入页面,然后调用按钮进行渲染.
第一次加载页面时,该按钮呈现正常.从/displaycode.php获取标记然后再次进行渲染调用时会出现问题.
<a href="javascript:void(0)" id="btn">REFRESH</a>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
{"parsetags": "explicit"}
</script>
<script type="text/javascript">
$(function() {
$("#btn").click(function() {
$('#live-preview').empty();
$("#live-preview").load('/displaycode.php #code');
gapi.plusone.go();
return false;
});
gapi.plusone.go();
});
</script>
<div id="live-preview"><div id="code"><div class="g-plusone"></div></div></div>
</div>
Run Code Online (Sandbox Code Playgroud)
可以在http://32px.co/googleplusdemo.php查看该问题的演示.在此先感谢您的帮助.
这已经涉及很多,似乎有不同的答案.我想为+1按钮实现我自己的文本(而不是图像).
这是我想要实现的,是否可能?

我无法弄清楚为什么我的Google +1按钮代码无法正常工作.
http://jsfiddle.net/DerekL/EF8eE/
当您按下+1按钮时,会alert弹出一个.
这里我有一个回调函数:
function cb(obj) {
alert(); //alert
console.log(obj); //Then show obj in console
}?
Run Code Online (Sandbox Code Playgroud)
但永远不会被回调.我根据规范遵循了每一步,最有趣的是我之前让它工作......但现在它根本不起作用.奇怪!
我已经在我的ios应用中集成了google plus,我能够成功登录,但我无法获取当前用户登录的电子邮件ID.我已经参考了https://developers.google.com/+/ mobile/ios /并遵循登录所需的所有步骤!
那么,我如何获得登录Google Plus的当前用户邮件ID?

我正在尝试使用+1 google api构建chrome扩展程序.
我的manifest.json看起来像:
"manifest_version": 2,
"content_security_policy": "script-src 'self' https://apis.google.com; object-src 'self'",
...
"matches": ["http://demosite.com/*"],
"js": ["js/jquery.js","js/social/plusone.js"]
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我将apis.google.com列入白名单.
我的plusone.js看起来像:
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "https://apis.google.com/js/plusone.js";
head.appendChild(script);
$('li.subscription').before('<g:plusone></g:plusone>');
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我只是从白名单网站注入脚本标记.
不幸的是,当我加载页面时出现错误:
拒绝加载脚本apis.google.com/ / scs/apps-static / /js/k=oz.gapi.ru.Fqrb4MMzOT8.O/m...sv=1/d=1/ed=1/am=IQ /rs=AItRSTNEKbnLkdtNZVz4hKH7VV4tY98scw/cb=gapi.loaded_0'因为它违反了以下内容安全策略指令:"script-src'self'".
这里所有类似的问题都说我应该使用content_security_policy将网站列入白名单,但我已经完成了,你可以看到.有什么想法有什么不对吗?
javascript google-chrome google-chrome-extension google-plus-one google-plus