如何获取谷歌+1计数当前页面在PHP? [英] How to get Google +1 count for current page in PHP?

查看:174
本文介绍了如何获取谷歌+1计数当前页面在PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想谷歌+ 1秒的计数当前网页?我想这样做在PHP这个过程中,然后写的股份数量或+ 1秒到数据库中。这就是为什么,我需要它。所以,我怎么能做到这个过程PHP(获得+1的计数)?

先谢谢了。

I want to get count of Google +1s for current web page ? I want to do this process in PHP, then write number of shares or +1s to database. That's why, I need it. So, How can I do this process (getting count of +1s) in PHP ?
Thanks in advance.

推荐答案

这一件作品对我来说,比快撇嘴:

This one works for me and is faster than the CURL one:

function getPlus1($url) {
    $html =  file_get_contents( "https://plusone.google.com/_/+1/fastbutton?url=".urlencode($url));
    $doc = new DOMDocument();   $doc->loadHTML($html);
    $counter=$doc->getElementById('aggregateCount');
    return $counter->nodeValue;
}

也是这里的鸣叫,引脚和Facebook的

also here for Tweets, Pins and Facebooks

function getTweets($url){
    $json = file_get_contents( "http://urls.api.twitter.com/1/urls/count.json?url=".$url );
    $ajsn = json_decode($json, true);
    $cont = $ajsn['count'];
    return $cont;
}

function getPins($url){
    $json = file_get_contents( "http://api.pinterest.com/v1/urls/count.json?callback=receiveCount&url=".$url );
    $json = substr( $json, 13, -1);
    $ajsn = json_decode($json, true);
    $cont = $ajsn['count'];
    return $cont;
}

function getFacebooks($url) { 
    $xml = file_get_contents("http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($url));
    $xml = simplexml_load_string($xml);
    $shares = $xml->link_stat->share_count;
    $likes  = $xml->link_stat->like_count;
    $comments = $xml->link_stat->comment_count; 
    return $likes + $shares + $comments;
}

请注意:Facebook的数字是喜欢+股份之和也有人说加评论(我没有搜索这个还),反正用一个你需要的

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.

这会工作,如果你的php设置允许开放的外部URL,请检查您的allow_url_openPHP设置。

This will works if your php settings allow open external url, check your "allow_url_open" php setting.

希望有所帮助。

这篇关于如何获取谷歌+1计数当前页面在PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆