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 secret.
My redirect URI exists and is:
http://localhost:8080/platform/soundcloudCallback.html
My code is as follows:
func main() {
v := url.Values{}
v.Set("scope", "non-expiring")
v.Set("client_id", auth.ClientID)
v.Set("response_type", "code")
v.Set("redirect_uri", auth.RedirectURI)
c.AuthURL = AuthEndpoint + "?" + v.Encode()
c.Values = v.Encode()
res := c.Request("POST", url.Values{})
}
func (c *Client) Request(method string, params url.Values) []byte {
params.Set("client_id", "*************")
reqUrl := "https://api.soundcloud.com/oauth2/token"
req, _ := http.NewRequest(method, reqUrl, strings.NewReader(c.Values))
req.Header.Add("Accept", "application/json")
resp, _ := c.client.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
return body
}
Is my body in the NewRequest incorrect or is something else causing the issue? It's very unclear how localhost works with the API.
The solution is ensuring you have all of the following:
v.Set("scope", "non-expiring")
v.Set("client_id", auth.ClientID)
v.Set("client_secret", "f5e416ddf95aed8d077fccccc0a07821")
v.Set("response_type", "code")
v.Set("redirect_uri", auth.RedirectURI)
v.Set("grant_type", "authorization_code")
For anyone stuck on this, I made a blog article at blog.rileedesign.com detailing everything.