AFHTTPClient を使用して残りの API 呼び出しを行おうとしています。登録から取得した認証キーをAPIに渡すことで、APIリクエストを作成しようとしています。アプリを実行すると、403 エラーが発生します。私は AFNetworking を使用するのが初めてで、これについて何か助けていただければ幸いです。
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://somewebsite.com/"]];
[httpClient setDefaultHeader:@"Authorization: Client-ID" value:@"xxxxxxxx"];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET"
path:@"https://api.somewebsite.com/api/category/subcategory/fun/"
parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// Print the response body in text
NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];