Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local http = require("http")
- local apiKey = "AIzaSyDQJ7SjasKcPq_bJhCyxuaoWiVydYTGDK0"
- local cx = "c3619c6476b78442f"
- local query = "https://www.googleapis.com/customsearch/v1?q=${encodeURIComponent(searchQuery)}&key=${apiKey}&cx=${cx}"
- local url = "https://www.googleapis.com/customsearch/v1?key=" .. apiKey .. "&cx=" .. cx .. "&q=" .. query
- local response = http.get(url)
- if response then
- local responseBody = response.readAll()
- response.close()
- local data = textutils.unserializeJSON(responseBody)
- -- Process and display search results
- -- Example: print the titles and URLs of the first few search results
- for i, item in ipairs(data.items) do
- print(i .. ": " .. item.title)
- print(" " .. item.link)
- end
- else
- print("Error: Failed to connect to Google API")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement