-
Notifications
You must be signed in to change notification settings - Fork 161
/
main.m
75 lines (54 loc) · 3.52 KB
/
main.m
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
//
// main.m
// streaming
//
// Created by Nicolas Seriot on 02/05/14.
// Copyright (c) 2014 Nicolas Seriot. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "STTwitter.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
STTwitterAPI *twitter = [STTwitterAPI twitterAPIOSWithFirstAccount];
#warning use your own tokens here
STTwitterAPI *twitter2 = [STTwitterAPI twitterAPIWithOAuthConsumerKey:@"" consumerSecret:@"" username:@"" password:@""];
[twitter verifyCredentialsWithUserSuccessBlock:^(NSString *username, NSString *userID) {
NSLog(@"-- Account: %@", username);
[twitter2 verifyCredentialsWithSuccessBlock:^(NSString *username) {
[twitter postStatusesFilterUserIDs:nil
keywordsToTrack:@[@"CocoaHeads"]
locationBoundingBoxes:nil
stallWarnings:nil
progressBlock:^(NSDictionary *json, STTwitterStreamJSONType type) {
if (type != STTwitterStreamJSONTypeTweet) {
NSLog(@"Invalid tweet (class %@): %@", [json class], json);
exit(1);
return;
}
printf("-----------------------------------------------------------------\n");
printf("-- user: @%s\n", [[json valueForKeyPath:@"user.screen_name"] cStringUsingEncoding:NSUTF8StringEncoding]);
printf("-- text: %s\n", [[json objectForKey:@"text"] cStringUsingEncoding:NSUTF8StringEncoding]);
NSString *idStr = [json objectForKey:@"id_str"];
NSString *responseText = [NSString stringWithFormat:@"Cocoaheads Yeah! %@", [NSDate date]];
[twitter2 postStatusesUpdate:responseText inReplyToStatusID:idStr latitude:nil longitude:nil placeID:nil displayCoordinates:nil trimUser:nil autoPopulateReplyMetadata:nil excludeReplyUserIDsStrings:nil attachmentURLString:nil useExtentedTweetMode:nil successBlock:^(NSDictionary *status) {
NSLog(@"-- status: %@", status);
} errorBlock:^(NSError *error) {
NSLog(@"-- error: %@", error);
}];
} errorBlock:^(NSError *error) {
NSLog(@"Stream error: %@", error);
exit(1);
}];
} errorBlock:^(NSError *error) {
NSLog(@"-- %@", [error localizedDescription]);
}];
} errorBlock:^(NSError *error) {
NSLog(@"-- %@", [error localizedDescription]);
exit(1);
}];
/**/
[[NSRunLoop currentRunLoop] run];
}
return 0;
}