-
Notifications
You must be signed in to change notification settings - Fork 54
/
app.js
49 lines (40 loc) · 1.41 KB
/
app.js
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
(function() {
var RUN_TESTS = false;
if (RUN_TESTS) {
Ti.include('tests/tests.js');
} else {
var accessTokenKey = Ti.App.Properties.getString('twitterAccessTokenKey'),
accessTokenSecret = Ti.App.Properties.getString('twitterAccessTokenSecret');
var Twitter = require('twitter').Twitter;
var client = Twitter({
consumerKey: "INSERT KEY HERE",
consumerSecret: "INSERT SECRET HERE",
accessTokenKey: accessTokenKey,
accessTokenSecret: accessTokenSecret
});
var win = Ti.UI.createWindow({backgroundColor: 'white'}),
tableView = Ti.UI.createTableView();
win.add(tableView);
win.open();
client.addEventListener('login', function(e) {
if (e.success) {
Ti.App.Properties.setString('twitterAccessTokenKey', e.accessTokenKey);
Ti.App.Properties.setString('twitterAccessTokenSecret', e.accessTokenSecret);
client.request("1/statuses/home_timeline.json", {count: 100}, 'GET', function(e) {
if (e.success) {
var json = JSON.parse(e.result.text),
tweets = json.map(function(tweet) {
return {title: tweet.text};
});
tableView.setData(tweets);
} else {
alert(e.error);
}
});
} else {
alert(e.error);
}
});
client.authorize();
}
})(this);