1
votes

I'm trying to use Spotify's Web API in a C# Form using this .Net Wrapper/API.

I want to create a Form where the user is able to enter his Username and Password and then the Program creates him a Playlist (using the Authorization Code Flow), but I'm failing at the authentication. I created a Project on the Web Api site and saved my ClientID and ClientSecret, but how would I get the access token and the refresh token? The API doesn't provide a example on this and I wasn't able to find a solution.

using SpotifyWebAPI;
using System;
using System.Windows.Forms;

namespace Spotify_Extender
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
            initialize();
        }

        private async void initialize()
        {
            var AuthenticationToken = new AuthenticationToken()
            {
                AccessToken = "",
                ExpiresOn = DateTime.Now.AddSeconds(3600),
                RefreshToken = "",
                TokenType = "Bearer"
            };

            // In a example the guy who made the API uses the Auth-Token to get the User,
            // so i assume up there you have to combine your clientToken with the credentials
            // or something like that
            var user = await SpotifyWebAPI.User.GetCurrentUserProfile(AuthenticationToken);

            MessageBox.Show(user.EmailAddress);

            var playlists = await user.GetPlaylists(AuthenticationToken);
        }
    }
}
1

1 Answers

0
votes

Refer to https://developer.spotify.com/web-api/authorization-guide/

There will be several steps before you could get access token and refresh token.

  1. Request authorization
  2. Login / Verify access
  3. Redirect back (with authorization code returned)
  4. Request access token and refresh token (require authorization code)

By creating an authorization access, you will be redirected to Spotify login screen so I don't think you need to enter username/password in your form. Just a button to login will do.