我想使用 twitterapi 获取推文并在 tableview 中显示。我实现了 twitter 框架的所有方法,如下所示。但我无法设置参数。
- (void)viewDidLoad
{
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=twitterapi&count=2"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:@"6253282" forKey:@"user_id"];
[parameters setObject:@"twitterapi" forKey:@"screen_name"];
[parameters setObject:@"true" forKey:@"include_entities"];
[parameters setObject:@"50" forKey:@"count"];
TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:parameters requestMethod:TWRequestMethodGET];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
self.dataSource = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
[self.tableView reloadData];
}
];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
我在使用 <[parameters setObject:@"" forKey:@""];> 和在 cellForRowAtIndexPath 中并不完美:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *tweet = [self.dataSource objectAtIndex:indexPath.row];
cell.textLabel.text = [tweet objectForKey:@"text"];
提前致谢和问候。