With the Reference to these Posts Objective-C equivalent of curl request ,Executing curl based actions in Objective-C i tried Below Code for my Example I have the example data like below
curl --get 'https://www.example.com/xyz' \
--user 'API_KEY:API_SECRET' \
--data 'app_id=APP_ID' \
--data 'metrics=users' \
--data 'dimensions=day,new_device' \
--data-urlencode 'conditions={"day":["between","2013-04-01","2013-04-07"]}'
How can I retrieve the data if I have the api key(production key),? and also how can I retrieve the data of users by using the above parameters? I tried doing it something like this , to pass the parameter to retrieve the data through the url .
-(void)doit
{
NSString *userName =@"abc@v.com";
NSString *password =@"cvbnm";
NSError *myError = nil;
NSMutableString *loginString = (NSMutableString*)[@"" stringByAppendingFormat:@"%@:%@", userName, password];
NSLog(@"loginstring=%@",loginString);
NSString *accept = [NSString stringWithFormat:@"application/example"];
NSLog(@"accept %@",accept);
NSString *authHeader = [@"Basic " stringByAppendingFormat:@"%@", loginString];
NSLog(@"auth header =%@",authHeader);
NSURL *url = [NSURL URLWithString:@"https://example.bnm/query"];
NSMutableURLRequest *request=[[NSMutableURLRequest alloc]init];
request = [NSMutableURLRequest requestWithURL:url];
[request setURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:@"users" forKey:@"metrics"];
[request setValue:@"value of api key" forKey:@"API_KEY"];
[request setValue:@"day" forKey:@"dimension"];
[request setValue:@"{"day":["between","2013-04-01","2013-04-07"]}" forKey:@"conditions"];
NSError *error;
NSURLResponse *response;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"data : %@",data);
NSString *result = [NSString stringWithCString:[data bytes] length:[data length]];
NSLog(@"result = %@",result);
}
But something went wrong and 'm not getting the proper response. Please do help me with this , please let me know how to fix it , any help will be really great , please let me know if you need more information