Skip to content

Instantly share code, notes, and snippets.

@jimmyjacobson
Created September 17, 2011 16:45
Show Gist options
  • Save jimmyjacobson/1224117 to your computer and use it in GitHub Desktop.
Save jimmyjacobson/1224117 to your computer and use it in GitHub Desktop.
Aggregating Users and Topics in Klout
<?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