Hi folks,
I'm new to Nim and trying to make a basic program that just gets some environment variables, makes a request to get a token, and then makes a request with the token. I'm using vs code and don't have any LSP errors showing, but when compiling I get an indentation error:
/.choosenim/toolchains/nim-1.6.14/lib/core/macros.nim(550, 3) Error: invalid indentation
After doing some searching around I think that this isn't actually an indentation problem but some other issue that's bubbling up to the compiler as a problem with indentation, but with no errors to really look at I don't know where the actual issue is. I'm sure it's something simple I'm missing but any help with tracking down would be greatly appreciated.
import std/[os, httpclient, strformat, json]
let id = getEnv("TWITCH_API_CLIENTID")
let secret = getEnv("TWITCH_API_CLIENT_SECRET")
proc getToken(): string =
let client = newHttpClient()
client.headers = newHttpHeaders({"Content-Type": "application/x-www-form-urlencoded"})
let resp = client.post("https://id.twitch.tv/oauth2/token", &"client_id={id}&client_secret={secret}&grant_type=client_credentials")
let json = parseJson(resp.body)
return json["access_token"].getStr()
proc getChannel(chan: string, token: string): string =
var client = newHttpClient()
client.headers = newHttpHeaders({"Authorization": &"Bearer {token}", "client_id": id})
let resp = client.get(&"https://api.twitch.tv/helix/search/channels?query={chan}")
return resp.body
let token = getToken()
echo &"Got response:\n{token}>>>>>>>>"
I suggest reinstalling your nim, it's likely you somehow modified your macros.nim and it's haunting you.
choosenim devel
choosenim remove stable
choosenim stable