public List <PicasaWebAlbum> QueryAlbums(BackgroundWorker worker, int overallJobPercent) { // Create an authentication factory to deal with logging in. GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName); authFactory.AccountType = "GOOGLE_OR_HOSTED"; this.m_albumQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("default")); this.m_albumQuery.Access = PicasaQuery.AccessLevel.AccessAll; this.m_albumService = new PicasaService(authFactory.ApplicationName); this.m_albumService.RequestFactory = authFactory; // this.m_albumService.setUserCredentials(this.m_userName, this.m_password); //string token = this.m_albumService.QueryAuthenticationToken(); this.m_albumService.SetAuthenticationToken(this.mUserToken); List <PicasaWebAlbum> retval = new List <PicasaWebAlbum>(); decimal count = ((decimal)overallJobPercent / 100) * 10; int smallCount = (int)count; try { worker.ReportProgress(0, (object)"Creating proxy"); CreateAlbumProxy(); worker.ReportProgress(smallCount, (object)"Proxy created"); worker.ReportProgress(0, (object)"Querying google"); this.m_albumFeed = this.m_albumService.Query(this.m_albumQuery); worker.ReportProgress(smallCount, (object)"Done"); } catch (Exception e) { this.m_albumQuery = null; this.m_albumService.RequestFactory = null; this.m_albumService = null; this.m_albumFeed = null; retval = null; throw new Exception("PicasaReader failed when downloading album feed for " + this.m_userName, e); } if (this.m_albumFeed.Entries.Count > 0) { int percent = (int)Math.Round((decimal)((overallJobPercent - (smallCount * 2)) / this.m_albumFeed.Entries.Count), 0); worker.ReportProgress(0, (object)"Processing album data"); foreach (PicasaEntry entry in this.m_albumFeed.Entries) { AlbumAccessor ac = new AlbumAccessor(entry); retval.Add(new PicasaWebAlbum(entry.Title.Text, entry.Updated, ac.NumPhotos, Convert.ToUInt64(ac.Id))); worker.ReportProgress(percent, null); } } this.m_albumQuery = null; this.m_albumService.RequestFactory = null; this.m_albumService = null; this.m_albumFeed = null; return(retval); }
private void buttonGetAlbumList_Click(object sender, EventArgs e) { authenticate(); string userName = comboLogin.Text; disableItemsForRun(); Thread thr = new Thread(new ThreadStart(delegate { try { AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(userName)); PicasaFeed feed = service.Query(query); Invoke(new MethodInvoker(delegate { listAlbums.Items.Clear(); albumMap.Clear(); foreach (PicasaEntry entry in feed.Entries) { AlbumAccessor ac = new AlbumAccessor(entry); listAlbums.Items.Add(ac.AlbumTitle); albumMap[ac.AlbumTitle] = ac; } if (feed.Entries.Count > 0) { listAlbums.SelectedIndex = 0; } buttonGetAlbumList.Enabled = true; updateItems(); })); } catch (Exception ex) { Invoke(new MethodInvoker(delegate { uploadLog.Text = "Album list upload failed: " + ex.Message + "\r\n"; listAlbums.Items.Clear(); albumMap.Clear(); updateItems(); })); } })); thr.Start(); }
public List <Album> GetList() { var service = new PicasaService("GPhotoSync"); service.SetAuthenticationToken(_credentials.AccessToken); var query = new AlbumQuery(); query.Thumbsize = "180"; query.Uri = new Uri(PicasaQuery.CreatePicasaUri(_credentials.User)); var feed = service.Query(query); if (feed != null) { var list = feed.Entries .OfType <PicasaEntry>() .Where(x => !IsPostEntry(x)) .OrderBy(x => x.Title.Text) .Select(x => { var accessor = new AlbumAccessor(x); var thumb = x.Media.Thumbnails[0]; using (var stream = service.Query(new Uri(thumb.Attributes["url"] as string))) { var ms = new MemoryStream(); stream.CopyTo(ms); ms.Seek(0, SeekOrigin.Begin); return(new Album { Id = accessor.Id, Title = accessor.AlbumTitle, ImageStream = ms, PhotoCount = (int)accessor.NumPhotos }); } }) .ToList(); return(list); } else { return(new List <Album>()); } }
public static AlbumSummary MapPicasaAlbum(PicasaEntry albumEntry) { if (!albumEntry.IsAlbum) { throw new ArgumentException("Entry is not an album.", "albumEntry"); } var album = new AlbumAccessor(albumEntry); return(new AlbumSummary { ID = album.Id, ThumbnailUri = new Uri(albumEntry.Media.Thumbnails[0].Url), Title = album.AlbumTitle, Description = album.AlbumSummary, PositionDateTime = albumEntry.Published }); }
protected void Page_Load(object sender, EventArgs e) { GotoAuthSubLink.Visible = false; if (Session["token"] != null) { Response.Redirect("Default.aspx"); } else if (Request.QueryString["token"] != null) { User u = new User(); u.Username = "******"; u.Password = "******"; PicasaService.setUserCredentials(u.Username, u.Password); AlbumQuery albumQuery = new AlbumQuery(); albumQuery.Uri = new Uri(PicasaQuery.CreatePicasaUri(u.Username)); //albumQuery.Access = PicasaQuery.AccessLevel.AccessPublic; PicasaFeed feed = PicasaService.Query(albumQuery); Session["feed"] = feed; Session["service"] = PicasaService; Session["user"] = u; if (feed.Entries.Count > 0) { AlbumAccessor myAlbum = new AlbumAccessor((PicasaEntry)feed.Entries[0]); Response.Redirect("Default.aspx?album=" + myAlbum.Id, true); } else { Response.Redirect("Default.aspx", true); } } else //no auth data, print link { GotoAuthSubLink.Text = "Login to your Google Account"; GotoAuthSubLink.Visible = true; GotoAuthSubLink.NavigateUrl = AuthSubUtil.getRequestUrl(Request.Url.ToString(), "https://picasaweb.google.com/data/", false, true); } }
/* public string LoginToGoogle(out string token) * { * GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName); * authFactory.AccountType = "GOOGLE_OR_HOSTED"; * * this.m_albumService = new PicasaService(authFactory.ApplicationName); * try * { * this.m_albumService.setUserCredentials(this.m_userName, this.m_password); * this.m_albumService.QueryAuthenticationToken(); // Authenticate the user immediately * } * catch (CaptchaRequiredException e) * { * token = e.Token; * return e.Url; * } * } * * public string LoginToGoogle(out string token, string CAPTCHAAnswer, string CAPTCHAToken) * { * GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName); * authFactory.AccountType = "GOOGLE_OR_HOSTED"; * string token = string.Empty; * this.m_albumService = new PicasaService(authFactory.ApplicationName); * authFactory.CaptchaAnswer = CAPTCHAAnswer; * authFactory.CaptchaToken = CAPTCHAToken; * this.m_albumService.setUserCredentials(this.m_userName, this.m_password); * * token = this.m_albumService.QueryAuthenticationToken(); // Authenticate the user immediately * return token; * * * } */ public List <PicasaWebAlbum> QueryAlbums() { // Create an authentication factory to deal with logging in. GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName); authFactory.AccountType = "GOOGLE_OR_HOSTED"; this.m_albumService = new PicasaService(authFactory.ApplicationName); this.m_albumService.RequestFactory = authFactory; this.m_albumService.SetAuthenticationToken(this.mUserToken); this.m_albumQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("default")); this.m_albumQuery.Access = PicasaQuery.AccessLevel.AccessAll; List <PicasaWebAlbum> retval = new List <PicasaWebAlbum>(); try { CreateAlbumProxy(); this.m_albumFeed = this.m_albumService.Query(this.m_albumQuery); } catch (Exception e) { this.m_albumQuery = null; this.m_albumService.RequestFactory = null; this.m_albumService = null; this.m_albumFeed = null; retval = null; throw new Exception("PicasaReader failed when downloading album feed for " + this.m_userName, e); } foreach (PicasaEntry entry in this.m_albumFeed.Entries) { AlbumAccessor ac = new AlbumAccessor(entry); retval.Add(new PicasaWebAlbum(entry.Title.Text, entry.Updated, ac.NumPhotos, Convert.ToUInt64(ac.Id))); } this.m_albumQuery = null; this.m_albumService.RequestFactory = null; this.m_albumService = null; this.m_albumFeed = null; return(retval); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Session["feed"] != null) { PicasaFeed feed = Session["feed"] as PicasaFeed; foreach (PicasaEntry entry in feed.Entries) { AlbumAccessor myAlbum = new AlbumAccessor((PicasaEntry)entry); entry.Etag = myAlbum.Id; } this.Repeater1.DataSource = feed.Entries; this.Repeater1.DataBind(); } if (Session["user"] != null) { Label_user.Text = ((User)Session["user"]).Username; } } }
protected string GetAlbumsTable() { if (string.IsNullOrEmpty(Settings.GetSingleValue("Account"))) { return(string.Empty); } var service = new PicasaService("exampleCo-exampleApp-1"); string usr = Settings.GetSingleValue("Account") + "@gmail.com"; string pwd = Settings.GetSingleValue("Password"); service.setUserCredentials(usr, pwd); var sb = new StringBuilder("<table class=\"beTable\">"); var query = new AlbumQuery(PicasaQuery.CreatePicasaUri(usr)); PicasaFeed feed = service.Query(query); sb.Append(GetHeader()); var cnt = 0; foreach (PicasaEntry entry in feed.Entries) { var ac = new AlbumAccessor(entry); const string cell = "<td>{0}</td>"; sb.Append(cnt % 2 == 0 ? "<tr>" : "<tr class=\"alt\">"); // thumbnail string albumUri = ((Google.GData.Client.AtomEntry)(entry)).AlternateUri.ToString(); string firstThumbUrl = entry.Media.Thumbnails[0].Attributes["url"] as string; string thumbAncr = string.Format("<a href=\"{2}\"><img src=\"{0}\" alt=\"{1}\" width=\"40\" /></a>", firstThumbUrl, entry.Title.Text, albumUri); sb.Append(string.Format(cell, thumbAncr)); // title sb.Append(string.Format(cell, ac.AlbumTitle)); // description sb.Append(string.Format(cell, ac.AlbumSummary + " ")); // number of photos sb.Append(string.Format(cell, ac.NumPhotos)); // access sb.Append(string.Format(cell, ac.Access)); // extension tag string feedUri = entry.FeedUri; const string showTag = "[PicasaShow:{0}]"; const string albmTag = "[PicasaAlbum:{0}]"; if (ac.Access.ToLower() == "protected") { sb.Append(string.Format(cell, " ")); sb.Append(string.Format(cell, " ")); } else { sb.Append(string.Format(cell, string.Format(showTag, ac.AlbumTitle))); sb.Append(string.Format(cell, string.Format(albmTag, ac.AlbumTitle))); } sb.Append("</tr>"); cnt++; } return(sb + "</table>"); }
private static string GetSlideShow(string albumId) { string s; try { var service = new PicasaService("exampleCo-exampleApp-1"); string usr = Settings.GetSingleValue("Account") + "@gmail.com"; string pwd = Settings.GetSingleValue("Password"); service.setUserCredentials(usr, pwd); var query = new AlbumQuery(PicasaQuery.CreatePicasaUri(usr)); PicasaFeed feed = service.Query(query); string id = ""; string key = ""; foreach (PicasaEntry entry in feed.Entries) { var ac = new AlbumAccessor(entry); if (ac.Name == albumId) { id = ac.Id; string feedUri = entry.FeedUri; if (feedUri.Contains("authkey=")) { string authKey = feedUri.Substring(feedUri.IndexOf("authkey=")).Substring(8); key = authKey; } } } if (key.Length > 0) { key = "authkey%3D" + key; } string user = Settings.GetSingleValue("Account"); string auto = ""; if (bool.Parse(Settings.GetSingleValue("AutoPlay")) == false) { auto = "&noautoplay=1"; } string width = Settings.GetSingleValue("ShowWidth"); string height = "96"; if (int.Parse(width) > 0) { height = (int.Parse(width) * 0.74).ToString(); } s = string.Format(Tag, id, key, user, auto, width, height); } catch (Exception exp) { s = exp.Message; } return(s); }