이 작업을 수행하는 데 약간의 시간이 걸렸으므로 다른 사람들을 위해 코드를 게시해야한다고 생각했습니다. 제 경우에는 특정 위치에 트윗을 가까이하려고했기 때문에 locations
매개 변수와 위치 범위 구조체를 사용했음을 알 수 있습니다. 원하는 매개 변수를 매개 변수 사전에 추가 할 수 있습니다.
또한이 계정은 기본 계정이 아니므로 계정을 찾을 수 없다는 사실을 사용자에게 알리는 등의 작업을 수행하고 여러 계정이있는 경우 사용할 트위터 계정을 선택할 수 있습니다.
해피 스트리밍 중!
//First, we need to obtain the account instance for the user's Twitter account
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request permission from the user to access the available Twitter accounts
[store requestAccessToAccountsWithType:twitterAccountType
withCompletionHandler:^(BOOL granted, NSError *error) {
if (!granted) {
// The user rejected your request
NSLog(@"User rejected access to the account.");
}
else {
// Grab the available accounts
NSArray *twitterAccounts = [store accountsWithAccountType:twitterAccountType];
if ([twitterAccounts count] > 0) {
// Use the first account for simplicity
ACAccount *account = [twitterAccounts objectAtIndex:0];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:@"1" forKey:@"include_entities"];
[params setObject:location forKey:@"locations"];
[params setObject:@"true" forKey:@"stall_warnings"];
//set any other criteria to track
//params setObject:@"words, to, track" [email protected]"track"];
// The endpoint that we wish to call
NSURL *url = [NSURL URLWithString:@"https://stream.twitter.com/1.1/statuses/filter.json"];
// Build the request with our parameter
TWRequest *request = [[TWRequest alloc] initWithURL:url
parameters:params
requestMethod:TWRequestMethodPOST];
// Attach the account object to this request
[request setAccount:account];
NSURLRequest *signedReq = request.signedURLRequest;
// make the connection, ensuring that it is made on the main runloop
self.twitterConnection = [[NSURLConnection alloc] initWithRequest:signedReq delegate:self startImmediately: NO];
[self.twitterConnection scheduleInRunLoop:[NSRunLoop mainRunLoop]
forMode:NSDefaultRunLoopMode];
[self.twitterConnection start];
} // if ([twitterAccounts count] > 0)
} // if (granted)
}];
그들이 쪼개 질 수 있다는 것을 몰랐습니다. – wbarksdale