Пример #1
0
        async Task UserLogin()
        {
            SpotifyAPI = await Spotify.UserLogin("7f08980f1dae4f3d98a40d44ef235b03");

            UserProfile = await SpotifyAPI.GetPrivateProfileAsync();

            txtUserProfile.Text          = "Logged in as: " + UserProfile.DisplayName;
            lvArticles.SelectionChanged += SelectedArticleChanged;
        }
        private void authResponseReceivedEvent(Models.Token token, string state)
        {
            mAuth.StopHttpServer();
            mSpotify = new SpotifyWebAPI();
            if (state != "XSS")
            {
                mErrorMessage = "Wrong state received.";
                return;
            }
            if (token.Error != null)
            {
                mErrorMessage = token.Error;
                return;
            }

            mSpotify.UseAuth     = true;
            mSpotify.AccessToken = token.AccessToken;
            mSpotify.TokenType   = token.TokenType;
            mProfile             = mSpotify.GetPrivateProfile();
        }
        public SpotifyUser(PrivateProfile oPrivateProfile, string sAuthCode, Token oToken)
        {
            this._SpotifyID = oPrivateProfile.Id;
            this._Name = oPrivateProfile.Id;
            this._ID = SpotifyAccessLayer.GetObjectIDForSpotifyID(this._SpotifyID);

            string sAccessCode = oToken.AccessToken;
            string sRefreshCode = oToken.RefreshToken;
            string sAccessTokenType = oToken.TokenType;
            int iAccessExpiresIn = oToken.ExpiresIn;
            DateTime dtToken = oToken.CreateDate.ToUniversalTime();
            DateTime dtAuth = oToken.CreateDate.ToUniversalTime();
            this._UserAuth = new SpotifyUserAuth(sAuthCode, dtAuth);
            SaveUserAndAuthToDatabase();
            this._RefreshToken = new SpotifyUserRefreshToken(sRefreshCode, dtToken);
            SaveRefreshTokenToDatebase();
            this._AccessToken = new SpotifyUserAccessToken(sAccessCode, sAccessTokenType, iAccessExpiresIn, dtToken);
            SaveAccessTokenToDatabase();
            this._UserGuid = SpotifyAccessLayer.GetUserGuidForUserID(this._ID);
        }
Пример #4
0
        private async void InitialSetup()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(InitialSetup));
                return;
            }

            authButton.Enabled = false;
            _profile = _spotify.GetPrivateProfile();

            _savedTracks = GetSavedTracks();
            savedTracksCountLabel.Text = _savedTracks.Count.ToString();
            _savedTracks.ForEach(track => savedTracksListView.Items.Add(new ListViewItem()
            {
                Text = track.Name,
                SubItems = { string.Join(",", track.Artists.Select(source => source.Name)), track.Album.Name }
            }));

            _playlists = GetPlaylists();
            playlistsCountLabel.Text = _playlists.Count.ToString();
            _playlists.ForEach(playlist => playlistsListBox.Items.Add(playlist.Name));

            displayNameLabel.Text = _profile.DisplayName;
            countryLabel.Text = _profile.Country;
            emailLabel.Text = _profile.Email;
            accountLabel.Text = _profile.Product;

            if (_profile.Images != null && _profile.Images.Count > 0)
            {
                using (WebClient wc = new WebClient())
                {
                    byte[] imageBytes = await wc.DownloadDataTaskAsync(new Uri(_profile.Images[0].Url));
                    using (MemoryStream stream = new MemoryStream(imageBytes))
                        avatarPictureBox.Image = Image.FromStream(stream);
                }
            }
        }
Пример #5
0
 public SpotifyUser AddSpotifyUser(PrivateProfile oPrivateProfile, string sAuthCode, Token oToken)
 {
     SpotifyUser oSpotifyUser = new SpotifyUser(oPrivateProfile, sAuthCode, oToken);
     return oSpotifyUser;
 }
Пример #6
0
        private List<TrackDetails> GetPlaylists()
        {
            while (check)
            {
                Thread.Sleep(250);
            };
            _profile = _spotify.GetPrivateProfile();
            Paging<SimplePlaylist> playlists = _spotify.GetUserPlaylists(_profile.Id);

            List<TrackDetails> listedTracks = new List<TrackDetails>();
            foreach (var ID in playlists.Items)
            {
                var details = _spotify.GetPlaylistTracks(_profile.Id, ID.Id);
                for (int i = 0; i < details.Total; i++)
                {
                    TrackDetails td = new TrackDetails();
                    td.title = details.Items[i].Track.Name;
                    td.artist = details.Items[i].Track.Artists[0].Name;
                    td.album = details.Items[i].Track.Album.Name;
                    td.albumArt = details.Items[i].Track.Album.Images[1].Url;
                    td.duration = details.Items[i].Track.DurationMs;
                    listedTracks.Add(td);
                }
            }
            return listedTracks.OrderBy(details => details.title).ToList();
        }
Пример #7
0
 private void Initialize()
 {
     if (InvokeRequired)
     {
         Invoke(new Action(Initialize));
         return;
     }
     AuthorizeButton.Enabled = false;
     profile = spotify.GetPrivateProfile();
     if (profile.HasError())
     {
         MessageBox.Show("Error retrieving profile:  " + profile.Error.Message, "SpotifyWeb API Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     MessageBox.Show("ID:  " + profile.Id);
 }