Created
May 9, 2011 19:27
-
-
Save miya0001/963205 to your computer and use it in GitHub Desktop.
Instagramの写真のパーマリンクからユーザーID、JsonのURL、AtomのURLを取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Author: Takayuki Miyauchi | |
URL: http://firegoby.theta.ne.jp/archives/2246 | |
*/ | |
class instagram { | |
private $json = "http://instagram.heroku.com/users/%s.json"; | |
private $atom = "http://instagram.heroku.com/users/%s.atom"; | |
function __construct() | |
{ | |
// nothing to do | |
} | |
public function getAtomURI($uid) | |
{ | |
$url = sprintf($this->atom, $uid); | |
return $url; | |
} | |
public function getJsonURI($uid) | |
{ | |
$url = sprintf($this->json, $uid); | |
return $url; | |
} | |
public function getUID($url) | |
{ | |
$dom = new DOMDocument(); | |
$dom->loadHTMLFile($url); | |
if (!$dom) { | |
return false; | |
} | |
$pimg = false; | |
foreach ($dom->getElementsByTagName('img') as $img) { | |
$class = $img->getAttribute('class'); | |
if (preg_match("/profile\-picture/", $class)) { | |
$pimg = basename($img->getAttribute('src')); | |
break; | |
} | |
} | |
if (preg_match("/^profile_([0-9]+)_.*$/", $pimg, $m)) { | |
return $m[1]; | |
} else { | |
return false; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment