-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
95 lines (85 loc) · 3.3 KB
/
index.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
$consumer_key = 'LH3oQv28gacLQfFIoMjj50';
$consumer_secret = '2Z13ObQn6KszRBq8EQXsvwcDDWqTVKb69KMo0SeqSjmk';
$access_token = '2826939806-V7uMmKFADJgmBMdtBhjUmeXOIi07';
$access_token_secret = 'MoTxGQXnRKCDm2eUPbkPtBbHoN9JwbeF0nNjBr3';
//Replace the acces tokens with your own values after creating a twitter app on developers.twitter.com
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
$connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);
$content = $connection->get("account/verify_credentials");
//$feed1 = $connection->get("application/rate_limit_status");
$currencies = array("Bitcoin","Ethereum","Bitcoin Cash","Ripple","Litecoin");
$len = count($currencies);
$feed = array($len);
for($x = 0; $x < $len; $x++) {
$arr = $connection->get("search/tweets",["q" => $currencies[$x], "count" => 100]);
$feed[$x] = json_encode($arr);
}
?>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script type="text/javascript">
// pass PHP variable declared above to JavaScript variable
var feedLength = <?php echo $len; ?>;
var feed = [];
feed.push(<?php echo $feed[0]; ?>);
feed.push(<?php echo $feed[1]; ?>);
feed.push(<?php echo $feed[2]; ?>);
feed.push(<?php echo $feed[3]; ?>);
feed.push(<?php echo $feed[4]; ?>);
//console.log(feed);
console.log("");
var fLen = feed.length;
if(fLen != feedLength){
alert("please update your feed array in javascript too.!!");
}
var sData = [];
for(var i=0; i<fLen;i++){
var sLen = feed[i].statuses.length;
for(var j=0;j<sLen;j++){
if(feed[i].statuses[j].lang == "en"){
var elements = {};
elements.id = feed[i].statuses[j].id;
elements.text = feed[i].statuses[j].text;
var hLen = feed[i].statuses[j].entities.hashtags.length;
if(hLen > 0){
var hashtags = " ";
for(var k=0;k<hLen;k++){
hashtags += feed[i].statuses[j].entities.hashtags[k].text + " ";
}
elements.hashtags = hashtags.trim();
}else{
elements.hashtags = "";
}
elements.user = {};
elements.user.id = feed[i].statuses[j].user.id;
elements.user.name = feed[i].statuses[j].user.name;
elements.user.location = feed[i].statuses[j].user.location;
elements.user.followers_count = feed[i].statuses[j].user.followers_count;
elements.user.friends_count = feed[i].statuses[j].user.friends_count;
elements.user.listed_count = feed[i].statuses[j].user.listed_count;
elements.user.created_at = feed[i].statuses[j].user.created_at;
elements.user.favourites_count = feed[i].statuses[j].user.favourites_count;
elements.user.time_zone = feed[i].statuses[j].user.time_zone;
elements.user.statuses_count = feed[i].statuses[j].user.statuses_count;
elements.user.lang = feed[i].statuses[j].user.lang;
elements.retweet_count = feed[i].statuses[j].retweet_count;
elements.favorite_count = feed[i].statuses[j].favorite_count;
elements.lang = feed[i].statuses[j].lang;
sData.push(elements);
}
}
}
var fd = JSON.stringify(sData);
$.ajax({
type: 'post',
url: 'http://localhost/twitter/database.php', //<--Note http
data: {feed:fd},
success: function( data ) {
console.log( data );
}
});
</script>