title: Soundcloud API Auth via Golang 401 Error
body: <p>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".</p>
  
  <p>I've verified client ID and secret. </p>
  
  <p>My redirect URI exists and is:    </p>
  
  <pre><code>http://localhost:8080/platform/soundcloudCallback.html
  </code></pre>
  
  <p>My code is as follows:</p>
  
  <pre><code>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
  }
  </code></pre>
  
  <p>Is my body in the NewRequest incorrect or is something else causing the issue? It's very unclear how localhost works with the API.</p>
  
  <p>The solution is ensuring you have all of the following:</p>
  
  <pre><code>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")
  </code></pre>
  
  <p>For anyone stuck on this, I made a blog article at blog.rileedesign.com detailing everything.</p>