Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let apiKey = ""
- let bundleId = ""
- let SearchEngineId = ""
- let serverAddress = String(format: "https://www.googleapis.com/customsearch/v1?
- q=%@&cx=%@&key=%@",KeyWord,SearchEngineId, apiKey)
- let url = serverAddress.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
- let finalUrl = URL(string: url!)
- let request = NSMutableURLRequest(url: finalUrl!, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10)
- request.httpMethod = "GET"
- request.setValue(bundleId, forHTTPHeaderField: "X-Ios-Bundle- Identifier")
- let session = URLSession.shared
- let datatask = session.dataTask(with: request as URLRequest) {
- (data, response, error) in
- do{
- if let jsonResult = try JSONSerialization.jsonObject(with:
- data!, options: []) as? NSDictionary{
- print("asyncResult(jsonResult)")
- }
- }
- catch let error as NSError{
- print(error.localizedDescription)
- }
- }
- datatask.resume()
Add Comment
Please, Sign In to add comment