It seems you are using a custom search API to embed in web pages.
This documentation is for what you want to do.
Here is an example of using as a search domain.
import UIKit import Alamofire class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() search(query: "swift") { (results) in for result in results { dump(result) } } } func search(query:String, completion: @escaping (Array<SearchResult>)->()){ let id = "Custom search engine ID" let key = "API key" let url = "https://www.googleapis.com/customsearch/v1?key=\(key)&cx=\(id)&q=\(query)" Alamofire.request(url).responseJSON { (response) in var results = Array<SearchResult>() if let dict = response.value as? Dictionary<String,Any> { if let items = dict["items"] as? Array<Dictionary<String,Any>> { for item in items { if let result = SearchResult(dict: item) { results.append(result) } else { print("Incomplete search result data.") } } } } completion(results) } } }
I have this structure to better save search results. It does not contain all the values ββthat give JSON results. I just selected them for testing.
struct SearchResult { var displayLink: String var formattedUrl: String var htmlFormattedUrl: String var htmlSnippet: String var htmlTitle: String var link: String var snippet: String var title: String init?(dict:Dictionary<String,Any>) { guard let displayLink = dict["displayLink"] as? String, let formattedUrl = dict["formattedUrl"] as? String, let htmlFormattedUrl = dict["htmlFormattedUrl"] as? String, let htmlSnippet = dict["htmlSnippet"] as? String, let htmlTitle = dict["htmlTitle"] as? String, let link = dict["link"] as? String, let snippet = dict["snippet"] as? String, let title = dict["title"] as? String else { return nil } self.displayLink = displayLink self.formattedUrl = formattedUrl self.htmlFormattedUrl = htmlFormattedUrl self.htmlSnippet = htmlSnippet self.htmlTitle = htmlTitle self.link = link self.snippet = snippet self.title = title } }
These are a few results that dump(result) prints.
βΏ CustomGoogleSearch.SearchResult - displayLink: "stackoverflow.com" - formattedUrl: "https://stackoverflow.com/questions/tagged/swift" - htmlFormattedUrl: "https://stackoverflow.com/questions/tagged/<b>swift</b>" - htmlSnippet: "<b>Swift</b> is an open-source programming language developed by Apple. Use the tag <br>\nonly for questions about language features, or requiring code in <b>Swift</b>. Use the ..." - htmlTitle: "Newest '<b>swift</b>' Questions - Stack Overflow" - link: "https://stackoverflow.com/questions/tagged/swift" - snippet: "Swift is an open-source programming language developed by Apple. Use the tag \nonly for questions about language features, or requiring code in Swift. Use the ..." - title: "Newest \'swift\' Questions - Stack Overflow" βΏ CustomGoogleSearch.SearchResult - displayLink: "stackoverflow.com" - formattedUrl: "stackoverflow.com/documentation/swift/topics" - htmlFormattedUrl: "stackoverflow.com/documentation/<b>swift</b>/topics" - htmlSnippet: "58 example-focused documentation topics for <b>Swift</b> Language." - htmlTitle: "All <b>Swift</b> Language Topics - Stack Overflow" - link: "http://stackoverflow.com/documentation/swift/topics" - snippet: "58 example-focused documentation topics for Swift Language." - title: "All Swift Language Topics - Stack Overflow"
Receiving keys
On this page, click the Get A Key button.

Then you need to select or create a Google project, then you will create an API key. So copy it here. let key = "API key"
For the search engine ID, go to the console . Now either select a search engine or create a new one. You will be taken to a page like this.

Press the Search engine ID button, a screen with your ID will appear on the screen, and then enter here let id = "Custom search engine ID"