å¿
è¦ã«ãªã£ãã®ã§å®è£
ãããtwitterãfacebookã¯å°ç¨ã®WebAPIãç¨æããã¦ãããã©ãGoogle+ã«é¢ãã¦ã¯ããããã¿ã³ããç¡çç¢çã«æ°åãæãåºããæãã§ãããããã¾ããã»ã¼ã³ãããªãã§ããï¼è»¢è¼å
ãããããã¨ãï¼ã
Â
Google+ã«ã¤ãã¦ã¯PHPã®OpenSSLãæå¹ã«ãªã£ã¦ããå¿
è¦ãããã¾ããphpinfo();ãªã©ã§èª¿ã¹ã¦æå¹ã«ãã¦ãã ããã
ããããOpenSSLã®ä»£æ¿æ¡ã¯LibreSSLã«ãªãã®ããªï¼ è¼ãæ¿ãã¦ããå ´åãPHPã®OpenSSLã©ã¤ãã©ãªã¯å¯¾å¿ãã¦ãããã ãããï¼ã使ãã¦ããããå¤å対å¿ãã¦ãããã ãããã©ãããã¾ã§ã¯èª¿ã¹ã¦ããªãã
Â
å®è£
ã¯ä¸è¨ã«ãªãã¾ãã
<?php class SocialMediaCount { public function __construct() { } public function getFacebookCount($url) { $json = json_decode(file_get_contents('http://graph.facebook.com/?id=' .urlencode($url))); if(isset($json->{'shares'})) { $param = $json->{'shares'}; } else { $param = 0; } return $param; } public function getTwitterCount($url) { $json = json_decode(file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' .urlencode($url))); return $json->{'count'}; } public function getGooglePlusCount($url) { // è¦OpenSSL $plus = file_get_contents('https://apis.google.com/_/+1/fastbutton?url=' .urlencode($url)); // æ£è¦è¡¨ç¾ã§ã«ã¦ã³ãæ°ã®ã¨ããã ããæ½åº preg_match( '/\[2,([0-9.]+),\[/', $plus, $count ); return $count[1]; } } $cntObj = new SocialMediaCount(); $url = 'http://www.google.co.jp'; echo $cntObj->getFacebookCount($url); echo "<br />"; echo $cntObj->getTwitterCount($url); echo "<br />"; echo $cntObj->getGooglePlusCount($url);
â åç
§ãµã¤ãæ§
Â
facebookã®APIã§ãããããæ°ãåå¾ããææ°ã®æ¹æ³ã¯ä½ãªãã ããï¼ã¨ãµã¨èª¿ã¹ã話 | ã«ãã¿ã ããã°
ç¹å®ã®URLã®ããã¤ã¼ãæ°ã»ãããæ°ãåå¾ããAPI - Qiita
Google+ã®ã«ã¦ã³ãæ°ãåå¾ããããã«è²ã
試ããçµæããã¡ã
Â