【问题标题】:Spotify API Access and Refresh TokenSpotify API 访问和刷新令牌
【发布时间】:2017-06-26 07:09:00
【问题描述】:

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

我想创建一个表单,用户可以在其中输入他的用户名和密码,然后程序为他创建一个播放列表(使用授权代码流),但我在身份验证失败。我在 Web Api 站点上创建了一个项目并保存了我的 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);
        }
    }
}

【问题讨论】:

    标签: c# spotify


    【解决方案1】:

    参考https://developer.spotify.com/web-api/authorization-guide/

    在您获得访问令牌和刷新令牌之前需要几个步骤。

    1. 请求授权
    2. 登录/验证访问权限
    3. 重定向回来(返回授权码)
    4. 请求访问令牌和刷新令牌(需要授权码)

    通过创建授权访问,您将被重定向到 Spotify 登录屏幕,因此我认为您无需在表单中输入用户名/密码。只需一个按钮即可登录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-05
      • 2018-08-01
      • 2022-07-15
      • 2022-10-08
      相关资源
      最近更新 更多