Skip to content

Instantly share code, notes, and snippets.

@aaronhoffman
Created September 14, 2016 17:39
Show Gist options
  • Save aaronhoffman/6383054e14427a22ddc11045f53b0e6e to your computer and use it in GitHub Desktop.
Save aaronhoffman/6383054e14427a22ddc11045f53b0e6e to your computer and use it in GitHub Desktop.
Spotify Web API Auth Example C#
public class SpotifyApiController
{
//see https://developer.spotify.com/web-api/authorization-guide/#client_credentials_flow
public void GetClientCredentialsAuthToken()
{
var spotifyClient = "";
var spotifySecret = "";
var webClient = new WebClient();
var postparams = new NameValueCollection();
postparams.Add("grant_type", "client_credentials");
var authHeader = Convert.ToBase64String(Encoding.Default.GetBytes($"{spotifyClient}:{spotifySecret}"));
webClient.Headers.Add(HttpRequestHeader.Authorization, "Basic " + authHeader);
var tokenResponse = webClient.UploadValues("https://accounts.spotify.com/api/token", postparams);
var textResponse = Encoding.UTF8.GetString(tokenResponse);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment