如何在IOS中检索Google搜索结果

时间:2016-02-01 16:27:03

标签: ios swift search google-search

我根据这篇文章设置了自定义Google搜索:What are the alternatives now that the Google web search API has been deprecated?

现在我需要在我的应用程序中实现它,我想发出搜索我的自定义搜索的请求,我需要处理我得到的结果(我相信JSON)。

我想我需要使用NSURLSession来发出请求,但我无法弄清楚正确的语法。

这是自定义搜索的网址:https://cse.google.com/cse/publicurl?cx=XXXXXXXXX:XXXXXXXXXX

1 个答案:

答案 0 :(得分:3)

修改此选项以满足您的需求:

googleUrl = "https://cse.google.com/cse/publicurl?cx=XXXXXXXXX:XXXXXXXXXX"
guard url = NSURL(string: googleUrl) else { return }
NSURLSession.sharedSession().dataTaskWithURL(url) {
    (data, response, error) in
    // deal with error etc accordingly       
}
相关问题