【发布时间】: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);
}
}
}
【问题讨论】: