如何在 PHP 中获取当前页面的 Google +1 计数?
我想获取当前网页的 Google +1 数量?我想在 PHP 中执行此过程,然后将股数或 +1 写入数据库。这就是为什么,我需要它。那么,我怎样才能在 PHP 中完成这个过程(获取 +1 的计数)?
提前致谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这个对我有用,比 CURL 更快:
这里也适用于推文、Pins 和 Facebook
注意:Facebook 数字是喜欢+分享的总和,有些人说加上评论(我还没有搜索这个),无论如何使用您需要的那个。
如果您的 php 设置允许打开外部 url,这将起作用,请检查您的“allow_url_open”php 设置。
希望有帮助。
This one works for me and is faster than the CURL one:
also here for Tweets, Pins and Facebooks
Note: Facebook numbers are the sum of likes+shares and some people said plus comments (I didn't search this yet), anyway use the one you need.
This will works if your php settings allow open external url, check your "allow_url_open" php setting.
Hope helps.
echo get_plusones("http://www.stackoverflow.com")
来自 internoetics.com
echo get_plusones("http://www.stackoverflow.com")
from internoetics.com
此处其他帖子中列出的 cURL 和 API 方式不再有效。
仍然至少有 1 种方法,但它很丑陋,而且 Google 显然不支持它。您只需使用正则表达式从官方按钮的 JavaScript 源代码中提取变量即可:
The cURL and API way listed in the other posts here no longer works.
There is still at least 1 method, but it's ugly and Google clearly doesn't support it. You just rip the variable out of the JavaScript source code for the official button with a regular expression:
到目前为止,下一个 PHP 脚本在检索 Google+ 的分享和 +1 计数方面效果很好。
The next PHP script works great so far for retrieving Google+ count on shares and +1's.
Google 目前没有用于获取 URL +1 计数的公共 API。您可以在此处提交功能请求。您还可以使用 逆向工程方法。请记住,尽管该方法可能随时更改和中断。
Google does not currently have a public API for getting the +1 count for URLs. You can file a feature request here. You can also use the reverse engineered method mentioned by @DerVo. Keep in mind though that method could change and break at anytime.
我已经编写了这段代码,以便直接从社交按钮使用的 iframe 中读取计数。
我还没有大规模测试它,所以也许你必须放慢请求和/或更改用户代理:)。
这是我的工作代码:
}
用法如下:
结果是:3166
I've assembled this code to read count directly from the iframe used by social button.
I haven't tested it on bulk scale, so maybe you've to slow down requests and/or change user agent :) .
This is my working code:
}
Usage is the following:
Result is: 3166
我必须合并来自不同选项和网址的一些想法,才能让它为我工作:
我所要做的就是更新网址,但我想为那些感兴趣的人发布一个完整的选项。
感谢卡迪使用这种方法,然后我只需要得到一个对我有用的网址......
I had to merge a few ideas from different options and urls to get it to work for me:
All I had to do was update the url but I wanted to post a complete option for those interested.
Thanks to Cardy for using this approach, then I just had to just get a url that worked for me...
我发布了一个 PHP 库,用于检索主要社交网络的计数。目前它支持 Google、Facebook、Twitter 和 Pinterest。
使用的技术与此处描述的技术类似,并且该库提供了一种缓存检索到的数据的机制。这个库还有一些其他不错的功能:可通过 Composer 安装、经过充分测试、HHVM 支持。
http://dunglas.fr/2014/01/introducing-the-社交共享-php-library/
I've released a PHP library retrieving count for major social networks. It currently supports Google, Facebook, Twitter and Pinterest.
Techniques used are similar to the one described here and the library provides a mechanism to cache retrieved data. This library also have some other nice features: installable through Composer, fully tested, HHVM support.
http://dunglas.fr/2014/01/introducing-the-socialshare-php-library/