Beispiel #1
0
        public SpotifyAPI(string clientId, string secretId, string redirectUrl = "http://localhost:4002", Boolean authed = false)
        {
            _clientId = clientId;
            _secretId = secretId;

            if (!authed)
            {
                System.Diagnostics.Debug.WriteLine("Authorizing for the first time");
                auth = new AuthorizationCodeAuth(
                    _clientId,
                    _secretId,
                    redirectUrl,
                    redirectUrl,
                    Scope.UserReadPrivate | Scope.UserReadCurrentlyPlaying | Scope.UserTopRead | Scope.Streaming | Scope.UserModifyPlaybackState | Scope.UserLibraryModify | Scope.UserReadPlaybackState | Scope.PlaylistReadPrivate | Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic | Scope.UserLibraryRead
                    );

                auth.AuthReceived += async(sender, payload) =>
                {
                    auth.Stop();
                    token = await auth.ExchangeCode(payload.Code);

                    api = new SpotifyWebAPI()
                    {
                        TokenType   = token.TokenType,
                        AccessToken = token.AccessToken
                    };
                    App.Current.Properties["TokenType"]   = api.TokenType;
                    App.Current.Properties["AccessToken"] = api.AccessToken;
                };
                auth.Start();
                auth.OpenBrowser();
                authed = true;
            }
        }
Beispiel #2
0
        private void connectBtn_Click(object sender2, EventArgs e)
        {
            String clientId     = clientIdTB.Text;
            String clientSecret = clientSecretTB.Text;

            if (clientId.Length > 0 && clientSecret.Length > 0)
            {
                AuthorizationCodeAuth auth = new AuthorizationCodeAuth(
                    clientId,
                    clientSecret,
                    "http://localhost:4002",
                    "http://localhost:4002",
                    Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic | Scope.UserLibraryModify
                    );

                auth.AuthReceived += async(sender, payload) =>
                {
                    auth.Stop();
                    Token token = await auth.ExchangeCode(payload.Code);

                    SpotifyAPI = new SpotifyWebAPI()
                    {
                        TokenType   = token.TokenType,
                        AccessToken = token.AccessToken
                    };
                };
                auth.Start(); // Starts an internal HTTP Server
                auth.OpenBrowser();
            }
            else
            {
                messageLbl.Text = "Need both client secret and client Id. These can be found on your spotify developer page (free to create account).";
            }
        }
Beispiel #3
0
        private static string _secretId = ""; //"";

        static void Main(string[] args)
        {
            _clientId = string.IsNullOrEmpty(_clientId)
                ? System.Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID")
                : _clientId;

            _secretId = string.IsNullOrEmpty(_secretId)
                ? System.Environment.GetEnvironmentVariable("SPOTIFY_SECRET_ID")
                : _secretId;

            Console.WriteLine("####### Spotify API Example #######");
            Console.WriteLine("This example uses AuthorizationCodeAuth.");
            Console.WriteLine(
                "Tip: If you want to supply your ClientID and SecretId beforehand, use env variables (SPOTIFY_CLIENT_ID and SPOTIFY_SECRET_ID)");


            AuthorizationCodeAuth auth =
                new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                          Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative);

            auth.AuthReceived += AuthOnAuthReceived;
            auth.Start();
            auth.OpenBrowser();

/*            ImplictGrantAuth auth = new ImplictGrantAuth("26d287105e31491889f3cd293d85bfea", "http://localhost:4002", "http://localhost:4002");
 *          auth.Start();
 *          auth.OpenBrowser();*/

            Console.ReadLine();
            auth.Stop(0);
        }
Beispiel #4
0
        private async void AuthOnAuthReceived(object sender, AuthorizationCode payload)
        {
            AuthorizationCodeAuth auth = (AuthorizationCodeAuth)sender;

            auth.Stop();

            Token token = await auth.ExchangeCode(payload.Code);

            api = new SpotifyWebAPI
            {
                AccessToken = token.AccessToken,
                TokenType   = token.TokenType
            };

            songInfo = await CurrentPlayingsong(api);


            if (songInfo == "")
            {
                return;
            }

            HappiWebApi happiapi = new HappiWebApi(_HappiapiKey);

            GetLyrics(happiapi, songInfo);
        }
Beispiel #5
0
        public SpotifyLoad()
        {
            auth = new AuthorizationCodeAuth(
                _clientId,
                _clientSecret,
                "http://localhost:4002",
                "http://localhost:4002",
                Scope.UserReadCurrentlyPlaying | Scope.UserModifyPlaybackState
                );

            auth.AuthReceived += async(sender, payload) =>
            {
                auth.Stop();
                token = await auth.ExchangeCode(payload.Code);

                api = new SpotifyWebAPI()
                {
                    TokenType   = token.TokenType,
                    AccessToken = token.AccessToken
                };
                Thread t = new Thread(spotifyDataLoop);
                t.Start();
            };
            auth.Start(); // Starts an internal HTTP Server
            auth.OpenBrowser();
        }
Beispiel #6
0
        public async void Init()
        {
            var _clientId = "4dab4bc197084c7db90f8201c5990abe";
            var _secretId = "e5f5c68a50ff48068eb1bfea84cc57a4";

            AuthorizationCodeAuth auth =
                new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                          Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative);

            auth.Start(); // Starts an internal HTTP Server
            auth.OpenBrowser();

            auth.AuthReceived += async(sender, payload) =>
            {
                auth.Stop();
                Token token = await auth.ExchangeCode(payload.Code);

                SpotifyWebAPI api = new SpotifyWebAPI()
                {
                    TokenType = token.TokenType, AccessToken = token.AccessToken
                };
                // Do requests with API client

                profile = await api.GetPrivateProfileAsync();

                if (!profile.HasError())
                {
                    Console.WriteLine(profile.DisplayName);
                }
            };
        }
Beispiel #7
0
        private static async void AuthOnAuthReceived(object sender, AuthorizationCode payload)
        {
            AuthorizationCodeAuth auth = (AuthorizationCodeAuth)sender;

            auth.Stop();

            Token token = await auth.ExchangeCode(payload.Code);

            api = new SpotifyWebAPI
            {
                AccessToken = token.AccessToken,
                TokenType   = token.TokenType
            };

            var result = GetsongInfo();

            if (!result.IsSuccess)
            {
                Console.WriteLine("Song Not found.");
                return;
            }


            songinfo = result.Date;
            GetLyrics(songinfo);
        }
        private static async Task <SpotifyWebAPI> AuthSpotifyApi()
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .Build();

            AuthorizationCodeAuth auth =
                new AuthorizationCodeAuth(
                    config.GetSection("SpotifyApi:ClientId").Value,
                    config.GetSection("SpotifyApi:ClientSecret").Value,
                    "http://localhost:6410",
                    "http://localhost:6410",
                    SpotifyAPI.Web.Enums.Scope.PlaylistReadCollaborative);

            auth.AuthReceived += async(sender, payload) =>
            {
                auth.Stop();
                Token token = await auth.ExchangeCode(payload.Code);

                _spotifyWeb = new SpotifyWebAPI()
                {
                    TokenType = token.TokenType, AccessToken = token.AccessToken
                };
                // Do requests with API client
            };
            auth.Start(); // Starts an internal HTTP Server
            auth.OpenBrowser();

            return(_spotifyWeb);
        }
        public async Task ConnectWebApi(bool keepRefreshToken = true)
        {
            _securityStore = SecurityStore.Load(pluginDirectory);

            AuthorizationCodeAuth auth = new AuthorizationCodeAuth(_securityStore.ClientId, _securityStore.ClientSecret, "http://localhost:4002", "http://localhost:4002",
                                                                   Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.UserReadCurrentlyPlaying | Scope.UserReadPlaybackState | Scope.UserModifyPlaybackState | Scope.Streaming | Scope.UserFollowModify);


            if (_securityStore.HasRefreshToken && keepRefreshToken)
            {
                Token token = await auth.RefreshToken(_securityStore.RefreshToken);

                _spotifyApi = new SpotifyWebAPI()
                {
                    TokenType = token.TokenType, AccessToken = token.AccessToken
                };
            }
            else
            {
                auth.AuthReceived += async(sender, payload) =>
                {
                    auth.Stop();
                    Token token = await auth.ExchangeCode(payload.Code);

                    _securityStore.RefreshToken = token.RefreshToken;
                    _securityStore.Save(pluginDirectory);
                    _spotifyApi = new SpotifyWebAPI()
                    {
                        TokenType = token.TokenType, AccessToken = token.AccessToken
                    };
                };
                auth.Start();
                auth.OpenBrowser();
            }
        }
Beispiel #10
0
        private static string _secretId = "b482925b5391423d8f2466288819b822"; //"";

        /*
         * Client ID b2931def6f7a47a981a43ea5c9c20c9e
         * Client Secret b482925b5391423d8f2466288819b822
         */


        // ReSharper disable once UnusedParameter.Local
        public static void Main(string[] args)
        {
            _clientId = string.IsNullOrEmpty(_clientId) ?
                        Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID") :
                        _clientId;

            _secretId = string.IsNullOrEmpty(_secretId) ?
                        Environment.GetEnvironmentVariable("SPOTIFY_SECRET_ID") :
                        _secretId;

            Console.WriteLine("####### Spotify API Example #######");
            Console.WriteLine("This example uses AuthorizationCodeAuth.");
            Console.WriteLine(
                "Tip: If you want to supply your ClientID and SecretId beforehand, use env variables (SPOTIFY_CLIENT_ID and SPOTIFY_SECRET_ID)");

            var auth =
                new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                          Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.PlaylistModifyPrivate | Scope.Streaming | Scope.AppRemoteControl | Scope.PlaylistModifyPublic | Scope.PlaylistReadPrivate | Scope.UserTopRead);

            auth.AuthReceived += AuthOnAuthReceived;



            auth.Start();
            auth.OpenBrowser();

            Console.ReadLine();
            auth.Stop(0);
        }
Beispiel #11
0
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            Environment.SetEnvironmentVariable("SPOTIFY_CLIENT_ID", "1f943e38b30c4a378c284f1ba0bafbf9");
            Environment.SetEnvironmentVariable("SPOTIFY_SECRET_ID", "7c100ccbb9714e13948a788b943636e8");

            _clientId = string.IsNullOrEmpty(_clientId)
                ? Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID")
                : _clientId;

            _secretId = string.IsNullOrEmpty(_secretId)
                ? Environment.GetEnvironmentVariable("SPOTIFY_SECRET_ID")
                : _secretId;

            Console.WriteLine("####### Spotify API Example #######");
            Console.WriteLine("This example uses AuthorizationCodeAuth.");
            Console.WriteLine(
                "Tip: If you want to supply your ClientID and SecretId beforehand, use env variables (SPOTIFY_CLIENT_ID and SPOTIFY_SECRET_ID)");

            AuthorizationCodeAuth auth = new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                                                   Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.AppRemoteControl | Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic | Scope.UserReadPrivate | Scope.UserReadEmail | Scope.Streaming
                                                                   | Scope.UserModifyPlaybackState | Scope.UserReadPlaybackState | Scope.UserReadRecentlyPlayed);

            auth.AuthReceived += AuthOnAuthReceived;
            auth.Start();
            auth.OpenBrowser();


            while (!end)
            {
            }

            //Thread.Sleep(1000000000);
            //Console.ReadLine();
            auth.Stop(0);
        }
Beispiel #12
0
 private void iniciarModoStream()
 {
     try
     {
         Log.Instance.ImprimirMensaje("Intentando conectar cuenta de Spotify", TipoMensaje.Info, "Spotify.iniciarModoStream()");
         Programa.HayInternet(true);
         Stopwatch crono = Stopwatch.StartNew();
         auth = new AuthorizationCodeAuth(
             clavePublica,
             clavePrivada,
             "http://localhost:4002/",
             "http://localhost:4002/",
             Scope.UserReadEmail | Scope.UserReadPrivate | Scope.Streaming | Scope.UserReadPlaybackState
             );
         auth.AuthReceived += (sender, payload) =>
         {
             auth.Stop();
             Token token = auth.ExchangeCode(payload.Code).Result;
             tokenActual = token;
             _spotify    = new SpotifyWebAPI()
             {
                 TokenType   = token.TokenType,
                 AccessToken = token.AccessToken
             };
             crono.Stop();
             if (_spotify.AccessToken != null)
             {
                 cuentaLista     = true;
                 cuentaVinculada = true;
                 Programa.config.AppSettings.Settings["VinculadoConSpotify"].Value = "true";
                 Log.Instance.ImprimirMensaje("Conectado sin errores como " + _spotify.GetPrivateProfile().DisplayName, TipoMensaje.Correcto, crono);
             }
             else
             {
                 cuentaLista     = false;
                 cuentaVinculada = false;
                 Log.Instance.ImprimirMensaje("Se ha conectado pero el token es nulo", TipoMensaje.Error, crono);
                 Programa.config.AppSettings.Settings["VinculadoConSpotify"].Value = "false";
             }
             CodigoRefresco = token.RefreshToken;
             Programa.tareaRefrescoToken = new Thread(Programa.Refresco);
             Programa.tareaRefrescoToken.Start();
         };
         auth.Start();
         auth.OpenBrowser();
     }
     catch (NullReferenceException)
     {
         Programa.HayInternet(false);
         Console.WriteLine("Algo fue mal");
         System.Windows.Forms.MessageBox.Show(Programa.textosLocal.GetString("error_internet"));
     }
     catch (HttpRequestException)
     {
         Programa.HayInternet(false);
         Console.WriteLine("No tienes internet");
         System.Windows.Forms.MessageBox.Show(Programa.textosLocal.GetString("error_internet"));
     }
 }
Beispiel #13
0
        private async void AuthOnAuthReceived(object sender, AuthorizationCode payload)
        {
            _authorizationCodeAuth = (AuthorizationCodeAuth)sender;
            _authorizationCodeAuth.Stop();

            _token = await _authorizationCodeAuth.ExchangeCode(payload.Code);

            RenewNextTokenRenewal();
        }
        private async void AuthOnAuthReceived(object Sender, AuthorizationCode Payload)
        {
            AuthorizationCodeAuth Auth = (AuthorizationCodeAuth)Sender;

            Auth.Stop();

            Token ReceivedToken = await Auth.ExchangeCode(Payload.Code);

            OnAuthCodeReceived(ReceivedToken.AccessToken, ReceivedToken.TokenType);
        }
Beispiel #15
0
        public void Dispose()
        {
            lcd.Dispose();

            spotTimer.Enabled = false;
            spotTimer.Dispose();
            spotTimer = null;

            lcdTimer.Enabled = false;
            lcdTimer.Dispose();
            lcdTimer = null;

            refreshTimer.Enabled = false;
            refreshTimer.Dispose();
            refreshTimer = null;

            initExcpt = null;
            auth.Stop(0);
        }
        private async void AuthOnAuthReceived(object sender, AuthorizationCode payload)
        {
            AuthorizationCodeAuth auth = (AuthorizationCodeAuth)sender;

            auth.Stop();

            Token token = await auth.ExchangeCode(payload.Code);

            this.Start(token);
        }
Beispiel #17
0
        private async void AuthOnAuthReceived(object sender, AuthorizationCode payload)
        {
            _authorizationCodeAuth = (AuthorizationCodeAuth)sender;
            _authorizationCodeAuth.Stop();

            _token = await _authorizationCodeAuth.ExchangeCode(payload.Code);

            // remember when to renew the 60 minutes token (10 minutes upfront)
            _nextTokenRenewal = DateTimeOffset.UtcNow.AddSeconds(_token.ExpiresIn).AddMinutes(-10);
        }
Beispiel #18
0
        private void OnAuthorizationRecieved(object sender, AuthorizationCode payload)
        {
            AuthorizationCodeAuth auth = sender as AuthorizationCodeAuth;

            auth.Stop();

            SAPIModels.Token token = auth.ExchangeCode(payload.Code).Result;
            Analysis.Log($"Gained the initial Spotify authorization at '{token.CreateDate}", Analysis.LogLevel.Vital);
            Configure(token, auth);
        }
        SpotifyConfiguration()
        {
            bool initialized = false;
            var  client_id   = "7b2f38e47869431caeda389929a1908e";
            var  secret_id   = "c3a86330ef844c16be6cb46d5e285a45";

            AuthenFactory = new AuthorizationCodeAuth(
                client_id,
                secret_id,
                "http://localhost:8888",
                "http://localhost:8888",
                SpotifyAPI.Web.Enums.Scope.AppRemoteControl
                );
            AuthenFactory.AuthReceived += async(s, p) =>
            {
                var ath = (AuthorizationCodeAuth)s;
                ath.Stop();

                var token = await ath.ExchangeCode(p.Code);

                initialized  = true;
                RefreshToken = token.RefreshToken;
                if (Client == null)
                {
                    Client = new SpotifyWebAPI()
                    {
                        AccessToken = token.AccessToken,
                        TokenType   = "Bearer"
                    };
                }
                else
                {
                    Client.AccessToken = token.AccessToken;
                }
                IsAvailable = true;
            };
            AuthenFactory.Start();
            AuthenFactory.OpenBrowser();
            while (!initialized)
            {
                System.Threading.Thread.Sleep(1000);
            }
            AuthenFactory.Stop();
            _refreshTokenWorker          = new Timer();
            _refreshTokenWorker.Interval = 30 * (1000 * 60);
            _refreshTokenWorker.Elapsed += async(s, e) =>
            {
                var token = await AuthenFactory.RefreshToken(RefreshToken);

                Client.AccessToken = token.AccessToken;
            };
            _refreshTokenWorker.Start();
        }
        private static async void AuthOnAuthReceived(object sender, AuthorizationCode payload)
        {
            AuthorizationCodeAuth auth = (AuthorizationCodeAuth)sender;

            auth.Stop();
            Token token = await auth.ExchangeCode(payload.Code);

            api = new SpotifyWebAPI {
                AccessToken = token.AccessToken,
                TokenType   = token.TokenType
            };
        }
        public static void Run(List <string> trackNames)
        {
            tracks = trackNames;

            AuthorizationCodeAuth auth = new AuthorizationCodeAuth(Credentials.SP_id,
                                                                   Credentials.SP_key, "http://localhost:4002", "http://localhost:4002", Scope.PlaylistModifyPrivate);

            auth.AuthReceived += AuthOnAuthReceived;
            auth.Start();
            auth.OpenBrowser();

            Console.ReadLine();
            auth.Stop(0);
        }
Beispiel #22
0
        static void Main(string[] args)
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new PlaylistMapper());
            });

            var serviceProvider = new ServiceCollection()
                                  .AddAutoMapper(typeof(Program))
                                  .AddSingleton <IValidator, Validator>()
                                  .AddSingleton <IProcessFactory, ProcessFactory>()
                                  .AddSingleton <IAPIProcess, ApiProcess>()
                                  .AddSingleton <SpotifyWebAPI>()
                                  .AddTransient <IProcess, GetPlaylistProcess>()
                                  .AddTransient <IProcess, ClearPlaylistProcess>()
                                  .AddTransient <IProcess, ReorderProcess>()
                                  .AddTransient <IServiceCollection, ServiceCollection>()
                                  .BuildServiceProvider();

            string _clientId = "eca82f597115423cac9d1125e0fb97c4";
            string _secretId = "17a6e5916bb3424eb50f29e4816521a4";

            AuthorizationCodeAuth auth = new AuthorizationCodeAuth(
                _clientId,
                _secretId,
                "http://localhost:4200",
                "http://localhost:4200",
                Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic
                );


            auth.AuthReceived += async(sender, payload) =>
            {
                auth.Stop();
                Token token = await auth.ExchangeCode(payload.Code);

                var apiProcess = serviceProvider.GetService <IAPIProcess>();

                ClearPlaylistRequest request = new ClearPlaylistRequest {
                    PlaylistUri = "6KPMCEavSTefLEx5JH3edt", Token = token
                };

                IResponseMessage responseMessage = apiProcess.RunCommand <ClearPlaylistRequest>(request);
            };
            auth.Start(); // Starts an internal HTTP Server
            auth.OpenBrowser();

            Console.ReadLine();
        }
        private async void OnAuthReceived(object sender, AuthorizationCode payload)
        {
            AuthorizationCodeAuth auth = (AuthorizationCodeAuth)sender;

            auth.Stop();
            Token token;

            token = await auth.ExchangeCode(payload.Code);

            spotify = new SpotifyWebAPI()
            {
                TokenType   = token.TokenType,
                AccessToken = token.AccessToken
            };
        }
Beispiel #24
0
        private static async void AuthOnAuthReceived(object sender, AuthorizationCode payload)
        {
            AuthorizationCodeAuth auth = (AuthorizationCodeAuth)sender;

            auth.Stop();

            SpotifyAPI.Web.Models.Token token = await auth.ExchangeCode(payload);

            SpotifyWebAPI api = new SpotifyWebAPI
            {
                AccessToken = token.AccessToken,
                TokenType   = token.TokenType
            };

            PrintUsefulData(api);
        }
Beispiel #25
0
        private void AuthorizeSpotifyToken()
        {
            AuthorizationCodeAuth auth = this.CreateAuthorization();

            auth.AuthReceived += async(sender, payload) =>
            {
                auth.Stop();
                Token token = await auth.ExchangeCode(payload.Code);

                this.CreateTokenFile(token);
                this.isAuthenticated = true;
            };

            auth.Start();
            auth.OpenBrowser();
        }
Beispiel #26
0
        /// <summary>
        /// Awaits the intial connection timeout if not recieved within given time
        /// </summary>
        /// <param name="timeoutSeconds"></param>
        /// <param name="auth"></param>
        /// <returns></returns>
        private System.Collections.IEnumerator AwaitConnectionTimeout(int timeoutSeconds, AuthorizationCodeAuth auth)
        {
            yield return(new WaitForSeconds(timeoutSeconds));

            if (IsConnecting && !IsConnected)
            {
                Analysis.LogError("Failed to get authentification - Timed out", Analysis.LogLevel.Vital);

                auth.Stop();
                auth.AuthReceived -= OnAuthorizationRecieved;

                IsConnecting = false;
            }

            m_timeoutRoutine = null;
        }
Beispiel #27
0
        private async void Auth_AuthReceived(object sender, AuthorizationCode payload)
        {
            AuthorizationCodeAuth auth = (AuthorizationCodeAuth)sender;

            auth.Stop();

            _token = await auth.ExchangeCode(payload.Code);

            _api = new SpotifyWebAPI
            {
                AccessToken = _token.AccessToken,
                TokenType   = _token.TokenType
            };

            RunSpotifyApi();
        }
Beispiel #28
0
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            SetApiKeys();

            AuthorizationCodeAuth auth =
                new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                          Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.UserReadCurrentlyPlaying);

            auth.AuthReceived += AuthOnAuthReceived;
            auth.Start();
            auth.OpenBrowser();
            Timer t = new Timer(TimerCallbackAsync, null, 0, 5000);

            Console.ReadLine();
            auth.Stop(0);
        }
Beispiel #29
0
        private static string _secretId = "3605d0cde2d74c07822299c0359f840f"; //"";


        // ReSharper disable once UnusedParameter.Local
        static public void Main()
        {
            //_clientId = string.IsNullOrEmpty(_clientId)
            //    ? Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID")
            //    : _clientId;

            //_secretId = string.IsNullOrEmpty(_secretId)
            //    ? Environment.GetEnvironmentVariable("SPOTIFY_SECRET_ID")
            //    : _secretId;


            //MainWindow mainMenu = new MainWindow();

            AuthorizationCodeAuth auth =
                new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                          Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.UserReadPlaybackState | Scope.UserModifyPlaybackState);

            //Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibraryRead |
            //Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate | Scope.UserTopRead | Scope.PlaylistReadCollaborative |
            //Scope.UserRead+RecentlyPlayed | Scope.UserReadPlaybackState | Scope.UserModifyPlaybackState)



            Console.WriteLine("Hello, open Spotify please and start a Playback");

            Console.WriteLine("Put the Emotic Epoc+ on your head please and open Emotiv App");
            Console.WriteLine("Select your Emotiv epoc+ device and follow the instructions given by the application ");
            Console.WriteLine("you must be 100 % of connection for the application work properly  ");
            Console.WriteLine("Press Enter when you are ready");
            Console.ReadLine();



            auth.AuthReceived += AuthOnAuthReceived;

            auth.Start();



            auth.OpenBrowser();

            Thread.Sleep(20000);
            Console.ReadLine();


            auth.Stop(0);
        }
Beispiel #30
0
        /// <summary>
        /// Authorize with the Spotify Web API to retrieve a Refresh Token.
        /// This token is then to be used for any subsequent calls to <see cref="RunStatus(Status)"/>
        /// </summary>
        /// <param name="opts_">CLI arguments</param>
        /// <returns>1 for errors, 0 otherwise</returns>
        static int RunAuthorize(Authorize opts_)
        {
            SysConsole.WriteLine("Authorizing with SpotifyWebAPI");

            Token token = null;
            var   auth  = new AuthorizationCodeAuth(opts_.ClientId, opts_.ClientSecret, "http://localhost:" + opts_.Port, "http://localhost:" + opts_.Port, Scope.UserReadPrivate);

            auth.AuthReceived += (object sender_, AuthorizationCode payload_) =>
            {
                auth.Stop();
                var exchange = auth.ExchangeCode(payload_.Code);
                exchange.Wait(10000);

                if (!exchange.IsCompleted)
                {
                    throw new Exception("Timeout during authorization process!");
                }

                token = exchange.Result;
            };

            SysConsole.WriteLine("Starting authorization process");
            auth.Start();
            auth.OpenBrowser();

            SysConsole.Write("Waiting for authorzation to complete...");
            while (token == null)
            {
                SysConsole.Write(".");
                Task.Delay(500).Wait();
            }

            string settings = "ClientId=" + opts_.ClientId + "\r\n";

            settings += "ClientSecret=" + opts_.ClientSecret + "\r\n";
            settings += "RefreshToken=" + token.RefreshToken + "\r\n";
            Clipboard.SetText(settings);

            SysConsole.WriteLine("");
            SysConsole.WriteLine("Token received. Set the following settings in your web parser parent measure:");
            SysConsole.WriteLine("---");
            SysConsole.WriteLine(settings);
            SysConsole.WriteLine("---");
            SysConsole.WriteLine("(the settings have been copied to your clipboard as well)");

            return(0);
        }