我想使用twitter API,但我遇到了错误。我有一个按钮,当我点击按钮时,我想看到推文。
#import "ViewController.h"
#import "AFHTTPSessionManager.h"
@interface ViewController ()
@end
@implementation ViewController
- (IBAction)transmit:(UIButton *)sender {
NSString *myString =@"https://api.twitter.com/1.1/search/tweets.json?q=&geocode=-22.912214,-43.230182,1km&lang=pt&result_type=recent";
NSURL *url=[NSURL URLWithString:myString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:myString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"data: %@", responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
它说错误:
2016-07-19 16:39:51.472 JSON[1377:77302] Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fdb1b607c00> { URL: https://api.twitter.com/1.1/search/tweets.json?q=&geocode=-22.912214,-43.230182,1km&lang=pt&result_type=recent } { status code: 400, headers {
"Content-Encoding" = gzip;
"Content-Length" = 87;
"Content-Type" = "application/json; charset=utf-8";
Date = "Tue, 19 Jul 2016 13:39:51 GMT";
Server = "tsa_a";
"Strict-Transport-Security" = "max-age=631138519";
"x-connection-hash" = 60ae6b2848e6b6cc27045899a9487783;
"x-response-time" = 3;
} }, NSErrorFailingURLKey=(TWITTER LINKS I CAN NOT WRITE IT BECAUSE OF MY REPUTATION) =<7b226572 726f7273 223a5b7b 22636f64 65223a32 31352c22 6d657373 61676522 3a224261 64204175 7468656e 74696361 74696f6e 20646174 612e227d 5d7d>, NSLocalizedDescription=Request failed: bad request (400)}
我搜索了但我无法解决这个问题。我该怎么做才能解决它?
答案 0 :(得分:0)
尝试使用此代码更改传输功能。
- (IBAction)transmit:(UIButton *)sender {
NSString *myString =@"https://api.twitter.com/1.1/search/tweets.json?q=&geocode=-22.912214,-43.230182,1km&lang=pt&result_type=recent";
NSString *Path = [myString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url=[NSURL URLWithString:Path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
}