English 中文(简体)
• 如何将谷歌+1计算在PHP的现有网页上?
原标题:How to get Google +1 count for current page in PHP?

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.

问题回答

这对我来说是有效的,而且比《欧洲增长和机会法》更快:

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;
}

这里还有Tweets, Pins和Facebook

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;
}

注:“Face”号是“等+共享”的总和,有些人说加上评论(但我没有这样做),任何方面都使用你所需要的数据。

如果您的实验室环境允许开放的外部陶尔,检查你的“allow_url_ open” php的设置。

希望有助于。

function get_plusones($url) {
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
  curl_setopt($curl, CURLOPT_POST, 1);
  curl_setopt($curl, 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($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_HTTPHEADER, array( Content-type: application/json ));
  $curl_results = curl_exec ($curl);
  curl_close ($curl);
  $json = json_decode($curl_results, true);
  return intval( $json[0][ result ][ metadata ][ globalCounts ][ count ] );
}

http://www.stackoverflow.com

http://www.internoetics.com/2007/05/16/count-comms-to-facebook-twitter-linkedin-googleplus/>internoetics.com

www.un.org/Depts/DGACM/index_spanish.htm 此处其他员额所列的“URL”和“APIC”方式不再有效。

至少有1种方法:,但 method和谷歌显然不支持。 你只是将 official本源代码中的变数与官方纽伦的定期表述相提并论:

function shinra_gplus_get_count( $url ) {
    $contents = file_get_contents( 
         https://plusone.google.com/_/+1/fastbutton?url=  
        . urlencode( $url ) 
    );

    preg_match(  /window.__SSR = {c: ([d]+)/ , $contents, $matches );

    if( isset( $matches[0] ) ) 
        return (int) str_replace(  window.__SSR = {c:  ,   , $matches[0] );
    return 0;
}

下一个PHP书迄今为止在重新检索谷歌+股份和+1 s方面做了大量工作。

$url =  http://nike.com ;
$gplus_type = true ?  shares  :  +1s ;

/**
 * Get Google+ shares or +1 s.
 * See out post at stackoverflow.com/a/23088544/328272
 */
function get_gplus_count($url, $type =  shares ) {
  $curl = curl_init();

  // According to stackoverflow.com/a/7321638/328272 we should use certificates
  // to connect through SSL, but they also offer the following easier solution.
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

  if ($type ==  shares ) {
    // Use the default developer key AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ, see
    // tomanthony.co.uk/blog/google_plus_one_button_seo_count_api.
    curl_setopt($curl, CURLOPT_URL,  https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ );
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, 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($curl, CURLOPT_HTTPHEADER, array( Content-type: application/json ));
  }
  elseif ($type ==  +1s ) {
    curl_setopt($curl, CURLOPT_URL,  https://plusone.google.com/_/+1/fastbutton?url= .urlencode($url));
  }
  else {
    throw new Exception( No $type defined, possible values are "shares" and "+1s". );
  }

  $curl_result = curl_exec($curl);
  curl_close($curl);

  if ($type ==  shares ) {
    $json = json_decode($curl_result, true);
    return intval($json[0][ result ][ metadata ][ globalCounts ][ count ]);
  }
  elseif ($type ==  +1s ) {
    libxml_use_internal_errors(true);
    $doc = new DOMDocument();
    $doc->loadHTML($curl_result);
    $counter=$doc->getElementById( aggregateCount );
    return $counter->nodeValue;
  }
}

// Get Google+ count.
$gplus_count = get_gplus_count($url, $gplus_type);

谷歌目前还没有一个用于计算URLs的+1的公益物。 https://code.google.com/p/google-plus-platform/issues/list”rel=“nofollow”>。 您也可使用reverse Engineering。 @DerVo. 提到的方法可以随时改变和打破。

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:

function get_plusone($url) 
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://plusone.google.com/_/+1/fastbutton?   
bsv&size=tall&hl=it&url=".urlencode($url));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$html = curl_exec ($curl);
curl_close ($curl);
$doc = new DOMDocument();
$doc->loadHTML($html);
$counter=$doc->getElementById( aggregateCount );
return $counter->nodeValue;

iii

使用如下:

echo get_plusones( http://stackoverflow.com/ );

结果:3166

我不得不将来自不同选择和ur的一些想法合并起来,以便让我为我工作:

function getPlusOnes($url) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, "https://plusone.google.com/_/+1/fastbutton?url=".urlencode($url));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        $html = curl_exec ($curl);
        curl_close ($curl);
        $doc = new DOMDocument();
        $doc->loadHTML($html);
        $counter=$doc->getElementById( aggregateCount );
        return $counter->nodeValue;
    }

我必须做的是更新这个词,但我想为感兴趣的人提出一个完整的选择。

echo getPlusOnes( http://stackoverflow.com/ )

由于使用这一方法的卡迪,我只得获得为我工作的一种ur。

I ve为主要社会网络发放了一张PHP图书馆检索表。 它目前支持谷歌、Facebook、Twitter和P interest。

所用技术与本文所述技术相似,图书馆提供了一个收集数据的机制。 该图书馆还拥有其他一些冰盖:通过Composer安装,经过充分测试,HHHVER支持。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签