如何获取 google plus +1 按钮的计数器?
我已在网站上添加了一个 google +1 按钮,但我想获取它的计数器,以便我可以对其进行一些数学计算。是否可以输入通过创建 +1 按钮的标准方法创建的 iframe,或者我需要进行一些调整吗?
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<g:plusone></g:plusone>
我尝试过此链接:1 ,但这不是很准确
I have added a google +1 button to a website, but I want to get it's counter so i can do some math over it. is it possible to enter the iframe created by the standard method of creating the +1 button or do I need to make some adjustment?
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<g:plusone></g:plusone>
I've tried this link:1 , but this is not very accurate
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您可以访问curl/file_get_contents/readfile/wget 或某种方式来获取外部URL,这非常简单。
加载以下网址:
https://plusone.google.com/_/+1/fastbutton?url=URLENCODED_URI
(已更新网址,请参阅下面的注释*)URLENCODED_URI 为您希望了解 +1 数量的网站,例如 http://www.google.com (http%3A%2F%2Fwww.google.com)
例如,获取 URI
https://plusone.google.com/_/+1/fastbutton?url=http://www.google.com /
(UPDATED URI) 并找到第一次出现的window.__SSR = {'c': 32414.0 ,'si'
。最好使用正则表达式,但我将把实现留给您和您选择的编程语言(服务器端或客户端)。'c'
后面的浮点数是该站点拥有的 +1 的数量。对于 google.com,这是 32,414。不用担心浮点数,您可以安全地将其转换为整数。* 更新: URL 已更新,旧 URL 开始为 404。请记住,这是预期的,因为这是非官方方法。目前还没有官方方法。
If you can access curl/file_get_contents/readfile/wget or some way to fetch an external URL, this is quite simple.
Load the following URL:
https://plusone.google.com/_/+1/fastbutton?url=URLENCODED_URI
(UPDATED URL, see note below *)URLENCODED_URI is the site you wish to know the number of +1's for, e.g. http://www.google.com (http%3A%2F%2Fwww.google.com)
For example, fetch the URI
https://plusone.google.com/_/+1/fastbutton?url=http://www.google.com/
(UPDATED URI) and locate the first occurance ofwindow.__SSR = {'c': 32414.0 ,'si'
. Preferably use regexp for this, but I'll leave the implementation to you and your chosen programming language (server side or client side).The float number following
'c'
is the number of +1's the site have. For google.com this is 32,414. Don't worry about the float, you can safely convert it to an integer.* UPDATE: The URL has been updated as the old URL started to 404. Remember, this is expected as this is an unofficial method. There exist no official method (yet).
您可以使用回调函数来获取显示计数的 div 的值吗?
我基于气泡注释按钮,我还没有测试过它但这样的事情应该有效。
Could you use a callback function to grab the value of the div that displays the count?
I'm basing this off the bubble annotation button, I haven't tested it but something like this should work.
适合我获取 Google Plus 计数器的纯客户端解决方案如下。它不需要 API 密钥。
然后我有一些带有积分的html
,这里转到这个答案。
A pure client-side solution that works for me to get the Google Plus counter is as follows. It does not need an API key.
Then I have some html with
Credits here goes to this answer.