public async Task <SpotifySearch> Search(string query, List <SpotifyConstants.SpotifySearchTypes> type, string market = null, int?limit = null, int?offset = null) { Url url = new Url(SpotifyConstants.BaseV1ApiUrl) .AppendPathSegment("search") .SetQueryParam("q", query) .SetQueryParam("type", string.Join(",", type.Select(t => SpotifyHelpers.SpotifySearchTypeToString(t)))) .SetQueryParam("market", market) .SetQueryParam("limit", limit) .SetQueryParam("offset", offset); return(await MakeAuthorizedSpotifyRequest <SpotifySearch>(url, HttpMethod.Get)); }
public async Task <SpotifyPagingObject <SpotifyAlbum> > GetArtistsAlbums(string id, List <SpotifyConstants.SpotifyArtistIncludeGroups> includeGroups = null, string market = null, int?limit = null, int?offset = null) { Url url = new Url(SpotifyConstants.BaseV1ApiUrl) .AppendPathSegments("artists", id, "albums"); if (includeGroups != null) { url.SetQueryParam("include_groups", string .Join(",", includeGroups.Select(includeGroup => SpotifyHelpers.SpotifyArtistIncludeGroupsToString(includeGroup)))); } url.SetQueryParam("market", market) .SetQueryParam("limit", limit) .SetQueryParam("offset", offset); return(await MakeAuthorizedSpotifyRequest <SpotifyPagingObject <SpotifyAlbum> >(url, HttpMethod.Get)); }
public async Task <string> RequestAccessToken() { FormUrlEncodedContent tokenRequestContent = new FormUrlEncodedContent(new Dictionary <string, string>() { { "grant_type", "client_credentials" } }); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", SpotifyHelpers.GetEncodedAuth(clientId, clientSecret)); HttpResponseMessage responseMessage = await httpClient.PostAsync(SpotifyConstants.RequestAccessTokenUrl, tokenRequestContent); authenticationType = SpotifyConstants.AuthenticationType.ClientCredentials; return(await ProcessAuthorizationResponse(responseMessage)); }
public string GetAuthorizeUrl(List <SpotifyConstants.SpotifyScopes> scopes = null, string state = null) { return(SpotifyHelpers.GetAuthorizeUrl(clientId, redirectUrl, scopes, state)); }
public async Task <string> RefreshAccessToken() { if (authenticationType == SpotifyConstants.AuthenticationType.None) { throw new Exception("Client not authenticated yet."); } else if (authenticationType == SpotifyConstants.AuthenticationType.AuthorizationCode) { FormUrlEncodedContent refreshRequestContent = new FormUrlEncodedContent(new Dictionary <string, string>() { { "grant_type", "refresh_token" }, { "refresh_token", RefreshToken } }); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", SpotifyHelpers.GetEncodedAuth(clientId, clientSecret)); HttpResponseMessage responseMessage = await httpClient.PostAsync(SpotifyConstants.RequestAccessTokenUrl, refreshRequestContent); return(await ProcessAuthorizationResponse(responseMessage)); } else if (authenticationType == SpotifyConstants.AuthenticationType.ClientCredentials) { return(await RequestAccessToken()); } else { throw new NotImplementedException("New authorization type not implemented"); } }