Advertisement
nonogamer9

Untitled

Mar 18th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. local http = require("http")
  2.  
  3. local apiKey = "AIzaSyDQJ7SjasKcPq_bJhCyxuaoWiVydYTGDK0"
  4. local cx = "c3619c6476b78442f"
  5. local query = "https://www.googleapis.com/customsearch/v1?q=${encodeURIComponent(searchQuery)}&key=${apiKey}&cx=${cx}"
  6.  
  7. local url = "https://www.googleapis.com/customsearch/v1?key=" .. apiKey .. "&cx=" .. cx .. "&q=" .. query
  8.  
  9. local response = http.get(url)
  10.  
  11. if response then
  12. local responseBody = response.readAll()
  13. response.close()
  14.  
  15. local data = textutils.unserializeJSON(responseBody)
  16.  
  17. -- Process and display search results
  18. -- Example: print the titles and URLs of the first few search results
  19. for i, item in ipairs(data.items) do
  20. print(i .. ": " .. item.title)
  21. print(" " .. item.link)
  22. end
  23. else
  24. print("Error: Failed to connect to Google API")
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement