public ResultAlbums ListAlbums() { ResultAlbums resultListAlbums = new ResultAlbums(); List <AlbumData> listAlbums = new List <AlbumData>(); try { Uri uri = new Uri(GoogleConstants.URL_LIST_ALBUMS); RestClient client = new RestClient(uri); RestRequest request = new RestRequest(Method.GET); request.RequestFormat = DataFormat.Json; request.AddHeader("Authorization", "Bearer " + this.accessToken); bool hasMoreAlbums = true; while (hasMoreAlbums) { IRestResponse response = client.Execute(request); if (response.IsSuccessful) { ResultAlbums resultAlbums = JsonConvert.DeserializeObject <ResultAlbums>(response.Content); listAlbums.AddRange(resultAlbums.Albums); resultListAlbums.ResultCode = response.StatusCode.ToString(); resultListAlbums.ResultMessage = (response.ErrorMessage == "null") ? string.Empty : response.ErrorMessage; if (resultAlbums.NextPageToken != null) { request.AddParameter("pageToken", resultAlbums.NextPageToken); } else { resultListAlbums.Albums = listAlbums; hasMoreAlbums = false; } } else { ResultError resultError = JsonConvert.DeserializeObject <ResultError>(response.Content); resultListAlbums.ResultCode = response.StatusCode.ToString(); resultListAlbums.ResultMessage = (resultError.Error != null) ? resultError.Error.Message : "Erro"; hasMoreAlbums = false; } } } catch (Exception ex) { Console.WriteLine("Erro: " + ex.Message); } return(resultListAlbums); }
void bwListAlbums_DoWork(object sender, DoWorkEventArgs e) { ResultAlbums result = GooglePhotosInterface.Instance.ListAlbums(); if (result.ResultCode == "OK") { this.Invoke(new Action(() => { for (int i = 0; i < result.Albums.Count; i++) { AlbumData album = result.Albums[i]; AlbumControl albumControl = new AlbumControl(album); pnlAlbums.Controls.Add(albumControl); } })); } else { MessageBox.Show(result.ResultMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }