2017-02-08 75 views
0

私はSpotifyのWeb APIをthis .Net Wrapper/APIを使用してC#フォームで使用しようとしています。Spotify 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); 
     } 
    } 
} 

答えて

0

あなたがアクセストークンを取得し、トークンのリフレッシュができる前に、いくつかのステップがありますhttps://developer.spotify.com/web-api/authorization-guide/

を参照してください。承認を作成することにより

  1. リクエストの承認
  2. ログイン/確認しアクセスリダイレクトバック(認証コードで返される)
  3. リクエストアクセストークンとリフレッシュトークン(必要認証コード)

私はあなたのフォームにユーザー名/パスワードを入力する必要はないと思うので、Spotifyログイン画面にリダイレクトされます。ログインするだけのボタンがあります。

関連する問題