I\'m attempting to connect to the Soundcloud API and obtain a token in Golang, but I get a 401 errr saying, \"error\":\"invalid_client\".
I\'ve verified client ID and se
I don't know if you got the authentication process right. At first, you need to set up an app on SoundCloud - you have done that, because you have a client secret and a client id.
Then you open the SoundCloud login page, enter your username and password, and then (if you're logged in successfully) you're redirected to the Redirect URI with the authorization code. That code is very important, because with that code you can obtain the access token.
If you put in
v.Set("grant_type", "authorization_code")
you also need to set the authorization code with:
v.Set("code", AUTHORIZATION_CODE)
After that you'll get a response from SoundCloud with the access token, refresh token and so on..
EDIT:
So, for example your Redirect URI looks like this
http://redirect.uri
then, when the user authenticated successfully, you'll get redirected to that URI including the authentication code. It will look like this:
http://redirect.uri/?code=AUTHENTICATION_CODE
Then you make a POST request to
https://api.soundcloud.com/oauth2/token
including your authentication code, client id and client secret. The response will include the access token, refresh token and so on.
I think you also need to set the client secret, not only your client id.
I also wanted a non-expiring access token, but somehow this is not working. So I'm refreshing my access token everytime it is expired.
Maybe you want to check this.
Go implementation of Soundcloud Oauth2
https://github.com/vitorsvvv/go-soundcloud-oauth