在php不再工作的情况下获取google和twitter的共享计数
我使用以下函数获取社会份额计数:在php不再工作的情况下获取google和twitter的共享计数,php,twitter,google-plus,Php,Twitter,Google Plus,我使用以下函数获取社会份额计数: function get_tweets($url) { $json_string = $this->file_get_contents_curl('http://urls.api.twitter.com/1/urls/count.json?url=' . rawurlencode($url)); $json = json_decode($json_string, true); return isset($json['count'])
function get_tweets($url) {
$json_string = $this->file_get_contents_curl('http://urls.api.twitter.com/1/urls/count.json?url=' . rawurlencode($url));
$json = json_decode($json_string, true);
return isset($json['count'])?intval($json['count']):0;
}
function get_fb($url) {
$json_string = $this->file_get_contents_curl('http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls='.rawurlencode($url));
$json = json_decode($json_string, true);
return isset($json[0]['total_count'])?intval($json[0]['total_count']):0;
}
function get_pinterest($url) {
$return_data = $this->file_get_contents_curl('http://api.pinterest.com/v1/urls/count.json?url='.rawurlencode($url));
$json_string = preg_replace('/^receiveCount((.*))$/', "\1", $return_data);
$json = json_decode($json_string, true);
return isset($json['count'])?intval($json['count']):0;
}
private function file_get_contents_curl($url){
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
$cont = curl_exec($ch);
if(curl_error($ch))
{
die(curl_error($ch));
}
return $cont;
}
function get_plusones($url) {
$contents = file_get_contents('https://plusone.google.com/_/+1/fastbutton?url='.rawurlencode( $url ));
preg_match( '/window\.__SSR = {c: ([\d]+)/', $contents, $matches );
return isset($matches[0]) ? (int)str_replace('window.__SSR = {c: ', '', $matches[0]) : 0;
}
两天以来,twitter和谷歌都不再使用了,我发现以下错误:
failed to open stream: Connection timed out
我想我的ip已经被谷歌和推特禁止了,但我不确定。
有人能证实我的假设吗
如果我使用javascript解决方案,它会工作吗?php的手册:
CURLINFO_HTTP_代码将告诉您API服务器发送的HTTP响应代码。如果您在测试环境中,请尝试将其记录或打印在页面上。如果响应代码类似于403,则API服务器拒绝了从您的服务器发送的请求。作者附加了错误消息,这不是问题的正确答案。这应该是一个评论。