Hi. I recently started creating a Twitch bot, but I'm having trouble with the API/JSON.
I'll jump straight in and show my code and explain what's happening etc.
on *:SOCKOPEN:TwitchFollowers: {
if ($sockerr) { echo -ag Socket error! | halt }
else { echo -ag TwitchFollowers socket open. }
sockwrite -nt TwitchFollowers GET /kraken/channels/lynx876/follows HTTP/1.1
sockwrite -nt TwitchFollowers Host: twitch.tv
sockwrite -nt TwitchFollowers $crlf
sockread
}
on @*:TEXT:!followers:#: {
; if ($sslready) { echo -ag sslReady is true }
; else { echo -ag sslReady is false }
set %address api.twitch.tv
sockopen -e TwitchFollowers %address 443
}
on *:SOCKCLOSE:TwitchFollowers: {
echo -ag TwitchFollowers socket closed.
}
on *:SOCKREAD:TwitchFollowers: {
if ($sockerr) { echo -ag Socket error! | halt }
while (1) {
sockread %temp
; when nothing is read, the buffer was empty, so we return
if ($sockbr == 0) return
echo -ag sockread: %temp
}
}
The following is the output.
I
<SNIP>'ed some out, not sure if this is for my account only.
TwitchFollowers socket open.
sockread: HTTP/1.1 200 OK
sockread: Server: nginx
sockread: Date: Fri, 30 Aug 2013 01:53:45 GMT
sockread: Content-Type: application/json; charset=utf-8
sockread: Content-Length: 8628
sockread: Connection: close
sockread: status: 200 OK
sockread: x-api-version: 3
sockread: x-request-id: <SNIP>
sockread: via: Twice 0.2 twice8:3356
sockread: x-runtime: 0.830537
sockread: x-geo: GB
sockread: etag: "<SNIP>"
sockread: x-ua-compatible: IE=Edge,chrome=1
sockread: cache-control: max-age=0, private, must-revalidate
sockread: x-rack-cache: miss
sockread: Front-End-Https: on
sockread:
TwitchFollowers socket closed.
So, I see that 'Content-Type' is JSON. How would I go about parsing that data?
On
my followers json page, can I not just parse this as text?
If so, how do I actually go about getting the data in a variable instead of the above output when I connect?
Thanks for any help!