问题
i want to get the tweets and show in tableview using twitterapi. i implemented all the methods of twitter framework which are shown below . But i am not able to set the parameters.
- (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.
}
i am not perfect working with <[parameters setObject:@"" forKey:@""];> and in the cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *tweet = [self.dataSource objectAtIndex:indexPath.row];
cell.textLabel.text = [tweet objectForKey:@"text"];
thanks and regards in advance.
回答1:
As you are setting your parameters separately in a dictionary your url must be..
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/user_timeline.json"];
for more info you can follow here.
If you set the parameters both ways, the api uses from the url not the dictionary parameters set while request.
Just change your request url, it will work fine.
来源:https://stackoverflow.com/questions/12854323/how-to-set-parameters-of-twitterapi-to-display-tweets-in-uitableview