how to set parameters of twitterapi to display tweets in uitableview

那年仲夏 提交于 2019-12-25 03:12:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!