csmit195

Twitch Test Viewers

Sep 24th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.70 KB | None | 0 0
  1. os.loadAPI("json")
  2. local headers = {}
  3. headers['Client-ID'] = '2uiwi7gks15yxct7abpic82z66itg1'
  4. http.request("https://api.twitch.tv/helix/streams?user_id=82541781", nil, headers)
  5.  
  6. local requesting = true
  7.  
  8. while requesting do
  9.   local event, url, sourceText = os.pullEvent()
  10.  
  11.   if event == "http_success" then
  12.     local respondedText = sourceText.readAll()
  13.     local obj = json.decode(respondedText)
  14.     print(obj.data[1].viewer_count)
  15.     --local output = fs.open("out", "w")
  16.     --output.write(textutils.serialize(obj))
  17.     --output.close()
  18.     sourceText.close()
  19.    
  20.     requesting = false
  21.   elseif event == "http_failure" then
  22.     print("Server didn't respond.")
  23.    
  24.     requesting = false
  25.   end
  26. end
Advertisement
Add Comment
Please, Sign In to add comment