Spotify API访问和刷新令牌

时间:2017-02-08 15:18:33

标签: c# spotify

我尝试使用this .Net Wrapper / API在C#表单中使用Spotify的Web API。

我想创建一个表单,用户可以在其中输入用户名和密码,然后程序会为他创建一个播放列表(使用授权代码流程),但我没有通过身份验证。我在Web Api站点上创建了一个Project并保存了我的ClientID和ClientSecret,但是如何获取访问令牌和刷新令牌? API没有提供此示例,我也无法找到解决方案。

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 个答案:

答案 0 :(得分:0)

请参阅http://moduscreate.com/optimizing-react-es6-webpack-production-build/

在获得访问令牌和刷新令牌之前,将有几个步骤。

  1. 请求授权
  2. 登录/验证访问权限
  3. 重定向(返回授权码)
  4. 请求访问令牌和刷新令牌(需要授权码)
  5. 通过创建授权访问权限,您将被重定向到Spotify登录屏幕,因此我认为您不需要在表单中输入用户名/密码。只需一个登录按钮即可。

相关问题