-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_tweeter_users_occupations.php
More file actions
64 lines (57 loc) · 2.58 KB
/
list_tweeter_users_occupations.php
File metadata and controls
64 lines (57 loc) · 2.58 KB
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
<?php
/**
* Look for tweeter occupations.
*
* @param string $occupation
* The occupation that you are looking to get people Who are doing or achieve this.
* @return
*/
function list_tweeter_users_occupations($occupation = "", $count = 5) {
if (empty($occupation)) {
return '';
}
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "58298798-CJeFGysn7fhg7ov9yV8a0Hv6n2iLZNWSW5es10noo",
'oauth_access_token_secret' => "nqUwhbUavq7Szz2Vzkmes3VFgXQibxdkERGTl8fDtnHwj",
'consumer_key' => "RuRGuCqylE4kazQQvIODg",
'consumer_secret' => "Wii8B0xeVOxnArEqiuUJmOZb43SXcCx9wuwWkgPBFU"
);
$data_geop = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $_SERVER['REMOTE_ADDR']));
$country = !empty($data_geop['geoplugin_countryName']) ? $data_geop['geoplugin_countryName'] : '';
$country_code = !empty($data_geop['geoplugin_countryCode']) ? strtolower($data_geop['geoplugin_countryCode']) : '';
/** Perform a GET request and echo the response **/
/** Note: Set the GET field BEFORE calling buildOauth(); **/
$url = 'https://api.twitter.com/1.1/users/search.json';
//$url = 'https://api.twitter.com/1.1/search/tweets.json';
//$getfield = 'q=chef&geocode=-9.189967,-75.015152&lang=es';
$getfield = 'q=' . rawurlencode($occupation) . '+' . $country . '&count=' . $count;
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$result = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$users_list = json_decode($result);
$users = array();
$width = 200; ///< @TODO update this with Ricardo explanation.
$height = 200; ///< @TODO update this with Ricardo explanation.
foreach ($users_list as $user) {
$users[] = array(
'name' => $user->name,
'twitter_handle' => $user->screen_name,
'location' => !empty($user->location) ? $user->location : '',
'country' => $country,
'country_code' => $country_code,
'description' => !empty($user->description) ? $user->description : '',
'url' => !empty($user->url) ? $user->url : '',
'image' => !empty($user->profile_image_url_https) ? str_replace('normal', $width . 'x' . $height, $user->profile_image_url_https) : '',
);
}
return $users;
}
// LOGIC GOES HERE...
$occupation = !empty($_GET['occupation']) ? $_GET['occupation'] : '';
$count = !empty($_GET['count']) ? $_GET['count'] : 5;
print json_encode(list_tweeter_users_occupations($occupation, $count));
exit();