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

How to retrieve Google Search Results in IOS

我设置了自定义 Google 搜索 post:What are the alternatives now that the Google web search API has been deprecated?

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

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

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

根据您的需要修改此内容:

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       
}