Twitter タイムラインの取得表示
Twitterのタイムラインの取得には
こちらのページを参考にさせてもらいました。
大学院デビュー:TwitterFrameworkの利用
http://extendevernote.blogspot.jp/2012/02/twitterframework.html
こちらのページを参考にさせて頂いて
UITableにタイムラインを表示させることが出来ました。
APIコールを行うURLは
APIver1.1使用に変更になったので
https://api.twitter.com/1.1/statuses/home_timeline.jsonに変更。
ACAccountからタイムライン取得する部分はほとんど参考サイトのまま
画像取得してNSArrayに保存していくよう変更だけ加えました。
[_accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) { if(granted){ NSArray *accounts = [self->_accountStore accountsWithAccountType:accountType]; if (accounts != nil && [accounts count] != 0) { ACAccount *twAccount = [accounts objectAtIndex:0]; NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/home_timeline.json"]; NSLog(@"%@",[url absoluteString]); NSDictionary *params = [NSDictionary dictionaryWithObject:@"1" forKey:@"include_entities"]; SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:params]; request.account = twAccount; [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { if (urlResponse){ NSError *jsonError; NSArray *timeline = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&jsonError]; if(timeline){ NSString *output = [NSString stringWithFormat:@"HTTP response status: %ld",(long)[urlResponse statusCode]]; NSLog(@"%@", output); NSLog(@"%@",timeline); for (NSDictionary *tweet in timeline) { [tweetTextArray addObject:[tweet objectForKey:@"text"]]; NSDictionary *user = [tweet objectForKey:@"user"]; [userNameArray addObject:[user objectForKey:@"screen_name"]]; [tweetIconArray addObject:[user objectForKey:@"profile_image_url"]]; // つぶやきとユーザ名をダンプ NSLog(@"%@",tweet); NSLog(@"%@",[user objectForKey:@"screen_name"]); NSLog(@"%@",[user objectForKey:@"profile_image_url"]); NSLog(@"%lu",(unsigned long)[tweetIconArray count]); } [self.tableView reloadData]; }else{ NSLog(@"error: %@",jsonError); } } }]; } } }];
ほとんどそのままで利用出来たのですごく助かりました。
画像をUITableViewに表示する際のセルの高さは
前もって自動計算しないといけないのですが、自動計算の詳細がわからず
大きめに余白をとって表示させていて・・・わかったら書こうorz
他参考にしたサイト
Mac OSでも楽チン ツイート その2 Social.framework
http://blog.sigoo.jp/?p=112