-
Notifications
You must be signed in to change notification settings - Fork 10
/
klout.php
73 lines (61 loc) · 1.7 KB
/
klout.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
// contains $api_endpoint & $key
require_once 'config.inc.php';
/**
* Read data from Klout
*
* @see http://klout.com/s/developers/v2#intro
*/
class Klout {
/**
* Fetch the Klout id for the given Twitter name. Example:
* {
* "id":"1254747",
* "network":"ks"
* }
*
* @param string $service Valid services: twitter, klout, gp (Google+)
* @param string $account Username on said service
* @return string|false Klout id associated to given account, or false on failure
*/
public static function getId($service, $account) {
global $api_endpoint, $key;
$ch = curl_init($api_endpoint.'/identity.json/'.$service.'?key='.$key.'&screenName='.$account);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$info = curl_getinfo($ch);
if ($info['http_code'] != '404') {
$data_json = json_decode($data, true);
return $data_json['id'];
}
return false;
}
/**
* Fetch the Klout score for a Klout id. Example:
* {
* "score":39.02721402922333,
* "scoreDelta":
* {
* "dayChange":0.0033099139938457256,
* "weekChange":-0.6880237945155727,
* "monthChange":-1.5063959529033113
* },
* "bucket":"30-39"
* }
*
* @param string $id The Klout id of the user to fetch the score for
* @return array|false The Klout score & delta
*/
public static function getScore($id) {
global $api_endpoint, $key;
$ch = curl_init($api_endpoint.'/user.json/'.$id.'/score?key='.$key);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$info = curl_getinfo($ch);
if ($info['http_code'] != '404') {
$data_json = json_decode($data, true);
return $data_json;
}
return false;
}
}