Created
May 30, 2014 02:27
-
-
Save kmakita13714/949655ac5e2608b78474 to your computer and use it in GitHub Desktop.
SLRequestでTwitterのStreaming APIを利用する方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { | |
ACAccountStore *accountStore = [[ACAccountStore alloc] init]; | |
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; | |
__weak typeof(self) weakSelf = self; | |
[accountStore requestAccessToAccountsWithType:accountType | |
options:nil | |
completion:^(BOOL granted, NSError *error) { | |
if (granted) { | |
NSArray *accountArray = [accountStore accountsWithAccountType:accountType]; | |
if (accountArray.count > 0) { | |
ACAccount *account = accountArray[0]; | |
NSLog(@"%@", account); | |
NSLog(@"%@", account.identifier); | |
NSLog(@"%@", account.username); | |
NSURL *url = [NSURL URLWithString:@"https://userstream.twitter.com/1.1/user.json"]; | |
NSDictionary *params = nil; | |
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter | |
requestMethod:SLRequestMethodGET | |
URL:url | |
parameters:params]; | |
[request setAccount:account]; | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
weakSelf.connection = [NSURLConnection connectionWithRequest:request.preparedURLRequest | |
delegate:weakSelf]; | |
[weakSelf.connection start]; | |
}); | |
} | |
} | |
}]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data | |
{ | |
NSError *jsonError = nil; | |
id jsonObj = [NSJSONSerialization JSONObjectWithData:data | |
options:NSJSONReadingAllowFragments | |
error:&jsonError]; | |
NSLog(@"%@", jsonObj); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment