Last active
August 29, 2015 14:06
-
-
Save ustreamer-01647/50d2fcf56287af5eefaf to your computer and use it in GitHub Desktop.
TwitPic地引き
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 | |
// twitter screen_name | |
define("USERNAME", "paul_ga"); | |
// JSON保存フォルダ | |
define("JSONDIR", "json/"); | |
// JSON拡張子 | |
define("FILETAIL", ".json"); | |
// APIアドレス | |
define("URL", "http://api.twitpic.com/2/users/show.json?username="); | |
// ユーザページ始点は1 | |
define("USERPAGE_FIRST", 1); | |
// ユーザページ終点はHTTP 404が返るまで | |
define("USERPAGE_LAST", 256); | |
// get all page | |
if (1) { | |
for ($p = USERPAGE_FIRST; $p <= USERPAGE_LAST; $p++) { | |
echo USERNAME.$p."\n"; | |
if(false === saveUser(USERNAME, $p)){ | |
break; | |
} | |
} | |
} | |
//Warning: file_get_contents(http://api.twitpic.com/2/users/show.json?username=paul_ga&page=256): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found | |
saveUser(USERNAME, 2); | |
/** | |
* user jsonを保存する | |
* @param type $username twitterスクリーンネーム | |
* @param type $page ページ番号.省略時最新ページ0 | |
* @return type 書き込みバイト数またはbool(false) | |
*/ | |
function saveUser($username, $page = 0) { | |
$user = getUser($username, $page); | |
if (false === $user){ | |
return $user; | |
} | |
return file_put_contents(JSONDIR . $username . $page . FILETAIL, $user); | |
} | |
/** | |
* user jsonを取得する | |
* @param type $username twitterスクリーンネーム | |
* @param type $page ページ番号.省略時最新ページ0 | |
* @return type jsonまたはbool(false) | |
*/ | |
function getUser($username, $page = 0) { | |
$url = URL . $username . "&page=" . $page; | |
// HTTP 404のWarningは,返したfalseで制御すること | |
return @file_get_contents($url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docs and tool
http://dev.twitpic.com/docs/
http://dev.twitpic.com/docs/2/users_show
http://www.ctrlshift.net/jsonprettyprinter/