Created
July 24, 2015 19:47
-
-
Save woodwardtw/1c1d8feeff1083133d49 to your computer and use it in GitHub Desktop.
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 | |
$search = 'ecig'; | |
$url = 'https://api.instagram.com/v1/tags/' . $search .'/media/recent?client_id=YOUR_CLIENT_ID_HERE'; | |
$json = file_get_contents($url); | |
$obj = json_decode($json); | |
date_default_timezone_set('EST'); | |
$list = array(); | |
foreach ($obj->data as $media) { | |
$username = $media->user->username; | |
$likes = $media->likes->count; | |
$comments = $media->comments->count; | |
$link = $media->link; | |
$caption = $media->caption->text; | |
$filter = $media->filter; | |
$hashcount = substr_count($caption, '#'); | |
$hashtrue = (boolval($hashcount) ? 'true' : 'false'); | |
$atcount = substr_count($caption, '@'); | |
$attrue = (boolval($atcount) ? 'true' : 'false'); | |
array_push($list, $username . 'ˇ' . $likes . 'ˇ' . $comments . 'ˇ' . $link . 'ˇ' . $caption . 'ˇ' . $filter . 'ˇ' . date(DATE_RFC2822) . 'ˇ' . $hashtrue . 'ˇ' . $hashcount . 'ˇ' . $attrue . 'ˇ' .$atcount) ; | |
} | |
$file = fopen($search .'data.csv',"a+"); | |
foreach ($list as $line) | |
{ | |
fputcsv($file,explode('ˇ',$line)); | |
} | |
fclose($file); ?> | |
<?php | |
for ($x = 0; $x <= 10; $x++) { | |
$url = $url; | |
$next = $obj->pagination->next_url; | |
$url = $next; | |
$json = file_get_contents($url); | |
$obj = json_decode($json); | |
// echo $next . '<br>'; - was for testing url returns | |
$list = array(); | |
foreach ($obj->data as $media) { | |
$username = $media->user->username; | |
$likes = $media->likes->count; | |
$comments = $media->comments->count; | |
$link = $media->link; | |
$caption = $media->caption->text; | |
$filter = $media->filter; | |
$hashcount = substr_count($caption, '#'); | |
$hashtrue = (boolval($hashcount) ? 'true' : 'false'); | |
$atcount = substr_count($caption, '@'); | |
$attrue = (boolval($atcount) ? 'true' : 'false'); | |
array_push($list, $username . 'ˇ' . $likes . 'ˇ' . $comments . 'ˇ' . $link . 'ˇ' . $caption . 'ˇ' . $filter . 'ˇ' . date(DATE_RFC2822) . 'ˇ' . $hashtrue . 'ˇ' . $hashcount . 'ˇ' . $attrue . 'ˇ' .$atcount) ; | |
} | |
$file = fopen($search .'data.csv',"a+"); | |
foreach ($list as $line) | |
{ | |
fputcsv($file,explode('ˇ',$line)); | |
} | |
fclose($file); | |
}; | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment