Created
September 17, 2011 16:45
-
-
Save jimmyjacobson/1224117 to your computer and use it in GitHub Desktop.
Aggregating Users and Topics in Klout
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 | |
$user = $_GET["user"]; | |
$key= YOUR_KLOUT_KEY; | |
$response = array('user' => $user); | |
$topicUrl = "http://api.klout.com/1/users/topics.json?users=$user&key=$key"; | |
$json = file_get_contents($topicUrl,0,null,null); | |
$topics = json_decode($json); | |
$i = 0; | |
$response['topics'] = $topics->users[0]->topics; | |
$inflUrl = "http://api.klout.com/1/soi/influenced_by.json?users=$user&key=$key"; | |
$json = file_get_contents($inflUrl, 0, null, null); | |
$friends = json_decode($json); | |
$friendArray = array(); | |
foreach($friends->users[0]->influencers as $friend) { | |
array_push($friendArray, $friend->twitter_screen_name); | |
} | |
$user = implode($friendArray, ','); | |
$topicUrl = "http://api.klout.com/1/users/topics.json?users=$user&key=$key"; | |
$json = file_get_contents($topicUrl, 0, null, null); | |
$topics = json_decode($json); | |
$i = 0; | |
foreach($topics->users as $user) { | |
$response['influencers'][$i] = $user; | |
$i++; | |
} | |
print_r(json_encode($response)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment