public PicasaAlbum CreateAlbum(string title, string description, AlbumAccess access, DateTime pubDate) { if (title == null) { throw new ArgumentNullException("title"); } if (description == null) { description = ""; } if (access != AlbumAccess.Public && access != AlbumAccess.Private) { throw new ArgumentException("Invalid value.", "access"); } // Check if pubDate can be in the past string url = GDataApi.GetPostURL(conn.User); if (url == null) { throw new UnauthorizedAccessException("You are not authorized to create albums."); } string op_string = GetXmlForCreate(title, description, pubDate, access); byte [] op_bytes = Encoding.UTF8.GetBytes(op_string); HttpWebRequest request = conn.AuthenticatedRequest(url); request.ContentType = "application/atom+xml; charset=UTF-8"; request.Method = "POST"; Stream output_stream = request.GetRequestStream(); output_stream.Write(op_bytes, 0, op_bytes.Length); output_stream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string received = ""; using (Stream stream = response.GetResponseStream()) { StreamReader sr = new StreamReader(stream, Encoding.UTF8); received = sr.ReadToEnd(); } response.Close(); XmlDocument doc = new XmlDocument(); doc.LoadXml(received); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); XmlUtil.AddDefaultNamespaces(nsmgr); XmlNode entry = doc.SelectSingleNode("atom:entry", nsmgr); return(new PicasaAlbum(conn, null, entry, nsmgr)); }
/* (from gdata documentation...) * <entry xmlns='http://www.w3.org/2005/Atom' * xmlns:media='http://search.yahoo.com/mrss/' * xmlns:gphoto='http://schemas.google.com/photos/2007'> * <title type='text'>Trip To Italy</title> * <summary type='text'>This was the recent trip I took to Italy.</summary> * <gphoto:location>Italy</gphoto:location> * <gphoto:access>public</gphoto:access> * <gphoto:commentingEnabled>true</gphoto:commentingEnabled> * <gphoto:timestamp>1152255600000</gphoto:timestamp> * <media:group> * <media:keywords>italy, vacation</media:keywords> * </media:group> * <category scheme='http://schemas.google.com/g/2005#kind' * term='http://schemas.google.com/photos/2007#album'></category> * </entry> */ static string GetXmlForCreate(string title, string desc, DateTime date, AlbumAccess access) { var xml = new XmlUtil(); xml.WriteElementStringWithAttributes("title", title, "type", "text"); xml.WriteElementStringWithAttributes("summary", desc, "type", "text"); // location ? xml.WriteElementString("access", access.ToString().ToLower(CultureInfo.InvariantCulture), PicasaNamespaces.GPhoto); // commentingEnabled ? xml.WriteElementString("timestamp", ((long)(date - new DateTime(1970, 1, 1)).TotalSeconds * 1000).ToString(), PicasaNamespaces.GPhoto); //keywords ? xml.WriteElementStringWithAttributes("category", null, "scheme", "http://schemas.google.com/g/2005#kind", "term", "http://schemas.google.com/photos/2007#album"); return(xml.GetDocumentString()); }
private void ParseAlbum(XmlNode nodeitem, XmlNamespaceManager nsmgr) { System.Console.WriteLine(nodeitem.InnerText); title = nodeitem.SelectSingleNode("atom:title", nsmgr).InnerText; description = nodeitem.SelectSingleNode("media:group/media:description", nsmgr).InnerText; XmlNode node = nodeitem.SelectSingleNode("gphoto:id", nsmgr); if (node != null) { id = node.InnerText; } foreach (XmlNode xlink in nodeitem.SelectNodes("atom:link", nsmgr)) { if (xlink.Attributes.GetNamedItem("rel").Value == "alternate") { link = xlink.Attributes.GetNamedItem("href").Value; break; } } node = nodeitem.SelectSingleNode("gphoto:access", nsmgr); if (node != null) { string acc = node.InnerText; access = (acc == "public") ? AlbumAccess.Public : AlbumAccess.Private; } node = nodeitem.SelectSingleNode("gphoto:numphotos", nsmgr); if (node != null) { num_photos = (int)UInt32.Parse(node.InnerText); } node = nodeitem.SelectSingleNode("gphoto:numphotosremaining", nsmgr); if (node != null) { num_photos_remaining = (int)UInt32.Parse(node.InnerText); } node = nodeitem.SelectSingleNode("gphoto:bytesused", nsmgr); if (node != null) { bytes_used = (long)UInt64.Parse(node.InnerText); } }
/* (from gdata documentation...) <entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gphoto='http://schemas.google.com/photos/2007'> <title type='text'>Trip To Italy</title> <summary type='text'>This was the recent trip I took to Italy.</summary> <gphoto:location>Italy</gphoto:location> <gphoto:access>public</gphoto:access> <gphoto:commentingEnabled>true</gphoto:commentingEnabled> <gphoto:timestamp>1152255600000</gphoto:timestamp> <media:group> <media:keywords>italy, vacation</media:keywords> </media:group> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#album'></category> </entry> */ private static string GetXmlForCreate(string title, string desc, DateTime date, AlbumAccess access) { XmlUtil xml = new XmlUtil (); xml.WriteElementStringWithAttributes ("title", title, "type", "text"); xml.WriteElementStringWithAttributes ("summary", desc, "type", "text"); // location ? xml.WriteElementString ("access", access.ToString ().ToLower (CultureInfo.InvariantCulture), PicasaNamespaces.GPhoto); // commentingEnabled ? xml.WriteElementString ("timestamp", ((long)(date - new DateTime (1970, 1, 1)).TotalSeconds * 1000).ToString (), PicasaNamespaces.GPhoto); //keywords ? xml.WriteElementStringWithAttributes ("category", null, "scheme", "http://schemas.google.com/g/2005#kind", "term", "http://schemas.google.com/photos/2007#album"); return xml.GetDocumentString (); }
public PicasaAlbum CreateAlbum(string title, string description, AlbumAccess access, DateTime pubDate) { if (title == null) throw new ArgumentNullException ("title"); if (description == null) description = ""; if (access != AlbumAccess.Public && access != AlbumAccess.Private) throw new ArgumentException ("Invalid value.", "access"); // Check if pubDate can be in the past string url = GDataApi.GetPostURL (conn.User); if (url == null) throw new UnauthorizedAccessException ("You are not authorized to create albums."); string op_string = GetXmlForCreate (title, description, pubDate, access); byte [] op_bytes = Encoding.UTF8.GetBytes (op_string); HttpWebRequest request = conn.AuthenticatedRequest (url); request.AutomaticDecompression = DecompressionMethods.GZip; request.ContentType = "application/atom+xml; charset=UTF-8"; request.Method = "POST"; Stream output_stream = request.GetRequestStream (); output_stream.Write (op_bytes, 0, op_bytes.Length); output_stream.Close (); HttpWebResponse response = (HttpWebResponse) request.GetResponse (); string received = ""; using (Stream stream = response.GetResponseStream ()) { StreamReader sr = new StreamReader (stream, Encoding.UTF8); received = sr.ReadToEnd (); } response.Close (); XmlDocument doc = new XmlDocument (); doc.LoadXml (received); XmlNamespaceManager nsmgr = new XmlNamespaceManager (doc.NameTable); XmlUtil.AddDefaultNamespaces (nsmgr); XmlNode entry = doc.SelectSingleNode ("atom:entry", nsmgr); return new PicasaAlbum (conn, null, entry, nsmgr); }
public PicasaAlbum CreateAlbum(string title, string description, AlbumAccess access) { return CreateAlbum (title, description, access, DateTime.Now); }
public PicasaAlbum CreateAlbum(string title, AlbumAccess access) { return CreateAlbum (title, null, access, DateTime.Now); }
public PicasaAlbum CreateAlbum(string title, string description, AlbumAccess access) { return(CreateAlbum(title, description, access, DateTime.Now)); }
public PicasaAlbum CreateAlbum(string title, AlbumAccess access) { return(CreateAlbum(title, null, access, DateTime.Now)); }
private void ParseAlbum(XmlNode nodeitem, XmlNamespaceManager nsmgr) { title = nodeitem.SelectSingleNode ("atom:title", nsmgr).InnerText; description = nodeitem.SelectSingleNode ("media:group/media:description", nsmgr).InnerText; XmlNode node = nodeitem.SelectSingleNode ("gphoto:id", nsmgr); if (node != null) id = node.InnerText; foreach (XmlNode xlink in nodeitem.SelectNodes ("atom:link", nsmgr)) { if (xlink.Attributes.GetNamedItem ("rel").Value == "alternate") { link = xlink.Attributes.GetNamedItem ("href").Value; break; } } node = nodeitem.SelectSingleNode ("gphoto:access", nsmgr); if (node != null) { string acc = node.InnerText; access = (acc == "public") ? AlbumAccess.Public : AlbumAccess.Private; } node = nodeitem.SelectSingleNode ("gphoto:numphotos", nsmgr); if (node != null) num_photos = (int) UInt32.Parse (node.InnerText); node = nodeitem.SelectSingleNode ("gphoto:numphotosremaining", nsmgr); if (node != null) num_photos_remaining = (int) UInt32.Parse (node.InnerText); node = nodeitem.SelectSingleNode ("gphoto:bytesused", nsmgr); if (node != null) bytes_used = (long) UInt64.Parse (node.InnerText); }