1

I am developing an app that will make a google search from a text input entered by the user.

My question is, do i need to use the google api or is it possible to just make a URL fetch with the user text, like so:

user entered "Skype"

    NSURLSessionConfiguration * config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession * session = [NSURLSession sessionWithConfiguration:config];

NSURLRequest * request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"https://www.google.com/search?q=%@"], userInput];
NSURLSessionDataTask *data = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    NSDictionary *theDic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
    NSLog(@"%@", theDic);
}];
[data resume];

and in the returned data i will get all the results from the search "Skype". Is it possible?

thanks,

YYfim
  • 1,402
  • 1
  • 9
  • 24

1 Answers1

2

You're definitely going to want to use the actual API. You'll need to sign up and get an API key. Using the regular web search URL will give you back a webpage as a result, which is probably not want you want for interacting with in an iOS app.

Here is a link to the API and here is a link to this specific API call.

Your query will look something like this:

https://www.googleapis.com/customsearch/v1?key=<YOUR API KEY>&q=<YOUR QUERY>&cx=<CUSTOM SEARCH ENGINE ID>

Here is an answer with more info about the Custom Search API.

Community
  • 1
  • 1
Dima
  • 23,484
  • 6
  • 56
  • 83