-
Notifications
You must be signed in to change notification settings - Fork 0
/
getTwitterActivity.php
executable file
·93 lines (87 loc) · 2.7 KB
/
getTwitterActivity.php
1
<!-- BACHELOR PROJECT Summer semester 2013 Martin Hellwagner (0956048)--><html><head><title>Bachelor project</title><meta charset="utf-8"><?phpinclude "php/twitterLogin.php";getTwitterActivity($_GET["artist"]);// authenticating user and receiving datafunction getTwitterActivity($artist) { $consumer_key = "DLV3QIjB5OIAPcLBJWrKrw"; $consumer_secret = "euaJZksVhQh1csxIrBxLOeK8hEdOe190Kf3Xdme4U"; $access_token = "1466868276-Vao8lKVaUvA27hTQmQzZt3zxtTasn6Wt83K9u69"; $access_token_secret = "GOZILTVVw2IKezlQpHZO34WqRftUUoA2bZnyWo9kk"; $connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret); searchUser($artist, $connection);}// searching for artist and checking if the user account is verifiedfunction searchUser($artist, $connection) { $results = $connection->get("users/search", array("q" => $artist, "count" => "20")); $verifiedFound = false; for ($i = 0; $i < count($results); $i++) { $verified = $results[$i]->verified; if ($verified == 1) { $accountName = $results[$i]->name; $verifiedFound = true; break; } } if ($verifiedFound == true) { parseData($accountName, $connection, 0); } else { $output = "<br>Failure<br>"; echo $output; }}// parsing fetched datafunction parseData($artist, $connection, $page, $maxId, $activity, $index) { if ($page == 0) { $maxId = 0; $activity = array(); $index = 0; $results = $connection->get("search/tweets", array("q" => "@".$artist, "count" => "100", "result_type" => "mixed")); } else { $results = $connection->get("search/tweets", array("max_id" => $maxId, "q" => "@".$artist, "count" => "100", "result_type" => "mixed")); } $nextResults = $results->search_metadata->next_results; if ($nextResults == "" || $page == 5) { $output = "<br>"; for ($i = 0; $i < count($activity); $i++) { $output = $output.$activity[$i][0]." ----- ".$activity[$i][1]." ----- ".$activity[$i][2]." ----- ".$activity[$i][3]."<br>"; } echo $output; } $nextResults = substr($nextResults, 0, strpos($nextResults, "&")); $maxId = substr($nextResults, strpos($nextResults, "=") + 1); $tweets = $results->statuses; for ($i = 0; $i < count($tweets); $i++) { $tweet = $tweets[$i]; $date = $tweet->created_at; $location = $tweet->user->location; $timezone = $tweet->user->time_zone; $text = $tweet->text; if ($location == "") { $location = -1; } if ($timezone == "") { $timezone = -1; } if ($text == null || $text == "") { $text = 0; } if ($location != -1 || $timezone != -1) { $activity[$index] = array($date, $location, $timezone, $text); $index = $index + 1; } } $page = $page + 1; parseData($artist, $connection, $page, $maxId, $activity, $index);}?></head></html>