public string GetBlogImagesAlbum(string albumName, string blogId) { const string FEED_REL = "http://schemas.google.com/g/2005#feed"; // TODO: HACK: The deprecation-extension flag keeps the deprecated Picasa API alive. Uri picasaUri = new Uri("https://picasaweb.google.com/data/feed/api/user/default?deprecation-extension=true"); var picasaId = string.Empty; try { Uri reqUri = picasaUri; XmlDocument albumListDoc = AtomClient.xmlRestRequestHelper.Get(ref reqUri, CreateAuthorizationFilter(), "kind", "album"); var idNode = albumListDoc.SelectSingleNode(@"/atom:feed/gphoto:user", _nsMgr) as XmlElement; if (idNode != null) { var id = AtomProtocolVersion.V10DraftBlogger.TextNodeToPlaintext(idNode); picasaId = id; } foreach (XmlElement entryEl in albumListDoc.SelectNodes(@"/atom:feed/atom:entry", _nsMgr)) { XmlElement titleNode = entryEl.SelectSingleNode(@"atom:title", _nsMgr) as XmlElement; if (titleNode != null) { string titleText = AtomProtocolVersion.V10DraftBlogger.TextNodeToPlaintext(titleNode); if (titleText == albumName) { XmlNode numPhotosRemainingNode = entryEl.SelectSingleNode("gphoto:numphotosremaining/text()", _nsMgr); if (numPhotosRemainingNode != null) { int numPhotosRemaining; if (int.TryParse(numPhotosRemainingNode.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out numPhotosRemaining)) { if (numPhotosRemaining < 1) { continue; } } } string selfHref = AtomEntry.GetLink(entryEl, _nsMgr, FEED_REL, "application/atom+xml", null, reqUri); if (selfHref.Length > 1) { // TODO: HACK: This keeps the deprecated Picasa API alive. selfHref += "&deprecation-extension=true"; return(selfHref); } } } } } catch (WebException we) { HttpWebResponse httpWebResponse = we.Response as HttpWebResponse; if (httpWebResponse != null) { HttpRequestHelper.DumpResponse(httpWebResponse); if (httpWebResponse.StatusCode == HttpStatusCode.NotFound) { throw new BlogClientOperationCancelledException(); } } throw; } try { XmlDocument newDoc = new XmlDocument(); XmlElement newEntryEl = newDoc.CreateElement("atom", "entry", AtomProtocolVersion.V10DraftBlogger.NamespaceUri); newDoc.AppendChild(newEntryEl); XmlElement newTitleEl = newDoc.CreateElement("atom", "title", AtomProtocolVersion.V10DraftBlogger.NamespaceUri); newTitleEl.SetAttribute("type", "text"); newTitleEl.InnerText = albumName; newEntryEl.AppendChild(newTitleEl); XmlElement newSummaryEl = newDoc.CreateElement("atom", "summary", AtomProtocolVersion.V10DraftBlogger.NamespaceUri); newSummaryEl.SetAttribute("type", "text"); newSummaryEl.InnerText = Res.Get(StringId.BloggerImageAlbumDescription); newEntryEl.AppendChild(newSummaryEl); XmlElement newAccessEl = newDoc.CreateElement("gphoto", "access", photoNS.Uri); newAccessEl.InnerText = "private"; newEntryEl.AppendChild(newAccessEl); XmlElement newCategoryEl = newDoc.CreateElement("atom", "category", AtomProtocolVersion.V10DraftBlogger.NamespaceUri); newCategoryEl.SetAttribute("scheme", "http://schemas.google.com/g/2005#kind"); newCategoryEl.SetAttribute("term", "http://schemas.google.com/photos/2007#album"); newEntryEl.AppendChild(newCategoryEl); Uri postUri = picasaUri; XmlDocument newAlbumResult = AtomClient.xmlRestRequestHelper.Post(ref postUri, CreateAuthorizationFilter(), "application/atom+xml", newDoc, null); XmlElement newAlbumResultEntryEl = newAlbumResult.SelectSingleNode("/atom:entry", _nsMgr) as XmlElement; Debug.Assert(newAlbumResultEntryEl != null); return(AtomEntry.GetLink(newAlbumResultEntryEl, _nsMgr, FEED_REL, "application/atom+xml", null, postUri)); } catch (Exception) { // Ignore } // If we've got this far, it means creating the Open Live Writer album has failed. // We will now try and use the Blogger assigned folder. if (!string.IsNullOrEmpty(picasaId)) { var service = GetService(); var userInfo = service.BlogUserInfos.Get("self", blogId).Execute(); // If the PhotosAlbumKey is "0", this means the user has never posted to Blogger from the // Blogger web interface, which means the album has never been created and so there's nothing // for us to use. if (userInfo.BlogUserInfoValue.PhotosAlbumKey != "0") { // TODO: HACK: The deprecation-extension flag keeps the deprecated Picasa API alive. var bloggerPicasaUrl = $"https://picasaweb.google.com/data/feed/api/user/{picasaId}/albumid/{userInfo.BlogUserInfoValue.PhotosAlbumKey}?deprecation-extension=true"; return(bloggerPicasaUrl); } } // If we've got this far, it means the user is going to have to manually create their own album. throw new BlogClientFileTransferException("Unable to upload to Blogger", "BloggerError", "We were unable to create a folder for your images, please go to http://openlivewriter.org/tutorials/googlePhotoFix.html to see how to do this"); }
public string GetBlogImagesAlbum(string albumName) { const string FEED_REL = "http://schemas.google.com/g/2005#feed"; const string GPHOTO_NS_URI = "http://schemas.google.com/photos/2007"; Uri picasaUri = new Uri("https://picasaweb.google.com/data/feed/api/user/default"); try { Uri reqUri = picasaUri; XmlDocument albumListDoc = AtomClient.xmlRestRequestHelper.Get(ref reqUri, CreateAuthorizationFilter(), "kind", "album"); foreach (XmlElement entryEl in albumListDoc.SelectNodes(@"/atom:feed/atom:entry", _nsMgr)) { XmlElement titleNode = entryEl.SelectSingleNode(@"atom:title", _nsMgr) as XmlElement; if (titleNode != null) { string titleText = AtomProtocolVersion.V10DraftBlogger.TextNodeToPlaintext(titleNode); if (titleText == albumName) { XmlNamespaceManager nsMgr2 = new XmlNamespaceManager(new NameTable()); nsMgr2.AddNamespace("gphoto", "http://schemas.google.com/photos/2007"); XmlNode numPhotosRemainingNode = entryEl.SelectSingleNode("gphoto:numphotosremaining/text()", nsMgr2); if (numPhotosRemainingNode != null) { int numPhotosRemaining; if (int.TryParse(numPhotosRemainingNode.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out numPhotosRemaining)) { if (numPhotosRemaining < 1) { continue; } } } string selfHref = AtomEntry.GetLink(entryEl, _nsMgr, FEED_REL, "application/atom+xml", null, reqUri); if (selfHref.Length > 1) { return(selfHref); } } } } } catch (WebException we) { HttpWebResponse httpWebResponse = we.Response as HttpWebResponse; if (httpWebResponse != null) { HttpRequestHelper.DumpResponse(httpWebResponse); if (httpWebResponse.StatusCode == HttpStatusCode.NotFound) { throw new BlogClientOperationCancelledException(); } } throw; } XmlDocument newDoc = new XmlDocument(); XmlElement newEntryEl = newDoc.CreateElement("atom", "entry", AtomProtocolVersion.V10DraftBlogger.NamespaceUri); newDoc.AppendChild(newEntryEl); XmlElement newTitleEl = newDoc.CreateElement("atom", "title", AtomProtocolVersion.V10DraftBlogger.NamespaceUri); newTitleEl.SetAttribute("type", "text"); newTitleEl.InnerText = albumName; newEntryEl.AppendChild(newTitleEl); XmlElement newSummaryEl = newDoc.CreateElement("atom", "summary", AtomProtocolVersion.V10DraftBlogger.NamespaceUri); newSummaryEl.SetAttribute("type", "text"); newSummaryEl.InnerText = Res.Get(StringId.BloggerImageAlbumDescription); newEntryEl.AppendChild(newSummaryEl); XmlElement newAccessEl = newDoc.CreateElement("gphoto", "access", GPHOTO_NS_URI); newAccessEl.InnerText = "private"; newEntryEl.AppendChild(newAccessEl); XmlElement newCategoryEl = newDoc.CreateElement("atom", "category", AtomProtocolVersion.V10DraftBlogger.NamespaceUri); newCategoryEl.SetAttribute("scheme", "http://schemas.google.com/g/2005#kind"); newCategoryEl.SetAttribute("term", "http://schemas.google.com/photos/2007#album"); newEntryEl.AppendChild(newCategoryEl); Uri postUri = picasaUri; XmlDocument newAlbumResult = AtomClient.xmlRestRequestHelper.Post(ref postUri, CreateAuthorizationFilter(), "application/atom+xml", newDoc, null); XmlElement newAlbumResultEntryEl = newAlbumResult.SelectSingleNode("/atom:entry", _nsMgr) as XmlElement; Debug.Assert(newAlbumResultEntryEl != null); return(AtomEntry.GetLink(newAlbumResultEntryEl, _nsMgr, FEED_REL, "application/atom+xml", null, postUri)); }
public override BlogPost Parse(XmlElement entryNode, bool includeCategories, Uri documentUri) { BlogPost post = new BlogPost(); AtomEntry atomEntry = new AtomEntry(_atomVer, _atomNS, CategoryScheme, _nsMgr, documentUri, entryNode); post.Title = atomEntry.Title; post.Excerpt = atomEntry.Excerpt; post.Id = PostUriToPostId(atomEntry.EditUri); post.Permalink = atomEntry.Permalink; string content = atomEntry.ContentHtml; if (content.Trim() != string.Empty) { HtmlExtractor ex = new HtmlExtractor(content); int start, length; if (Options.SupportsExtendedEntries && ex.Seek("<a name=\"more\">").Success) { start = ex.Element.Offset; length = ex.Element.Length; if (ex.Seek("</a>").Success) { post.SetContents(content.Substring(0, start), content.Substring(ex.Element.Offset + ex.Element.Length)); } else { post.SetContents(content.Substring(0, start), content.Substring(start + length)); } } else { post.Contents = content; } } post.DatePublished = atomEntry.PublishDate; if (Options.SupportsCategories && includeCategories) post.Categories = atomEntry.Categories; return post; }
public async Task <string> GetBlogImagesAlbum(string albumName) { const string FEED_REL = "http://schemas.google.com/g/2005#feed"; const string GPHOTO_NS_URI = "http://schemas.google.com/photos/2007"; Uri picasaUri = new Uri("https://picasaweb.google.com/data/feed/api/user/default"); try { Uri reqUri = picasaUri; var albumListDoc = await AtomClient.xmlRestRequestHelper.Get(await CreateAuthorizationFilter(), new XmlRestRequestHelper.XmlRequestResult() { uri = reqUri }, "kind", "album"); foreach (var entryEl in albumListDoc.SelectNodesNS(@"/atom:feed/atom:entry", _nsMgr.ToNSMethodFormat())) { var titleNode = entryEl.SelectSingleNodeNS(@"atom:title", _nsMgr.ToNSMethodFormat()); if (titleNode != null) { string titleText = AtomProtocolVersion.V10DraftBlogger.TextNodeToPlaintext(titleNode); if (titleText == albumName) { XmlNamespaceManager nsMgr2 = new XmlNamespaceManager(new NameTable()); nsMgr2.AddNamespace("gphoto", "http://schemas.google.com/photos/2007"); var numPhotosRemainingNode = entryEl.SelectSingleNodeNS("gphoto:numphotosremaining/text()", nsMgr2.ToNSMethodFormat()); if (numPhotosRemainingNode != null) { int numPhotosRemaining; if (int.TryParse((string)numPhotosRemainingNode.NodeValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out numPhotosRemaining)) { if (numPhotosRemaining < 1) { continue; } } } string selfHref = AtomEntry.GetLink(entryEl, _nsMgr, FEED_REL, "application/atom+xml", null, reqUri); if (selfHref.Length > 1) { return(selfHref); } } } } } catch (WebException we) { HttpWebResponse httpWebResponse = we.Response as HttpWebResponse; if (httpWebResponse != null) { HttpRequestHelper.DumpResponse(httpWebResponse); if (httpWebResponse.StatusCode == HttpStatusCode.NotFound) { throw new BlogClientOperationCancelledException(); } } throw; } throw new Exception("Could not find a Google Photos album called 'NetWriter'. Create an Album in Google Photos called 'NetWriter' and try again."); //var newDoc = new Windows.Data.Xml.Dom.XmlDocument(); //var newEntryEl = newDoc.CreateElementNS(AtomProtocolVersion.V10DraftBlogger.NamespaceUri, "atom:entry"); //newDoc.AppendChild(newEntryEl); //var newTitleEl = newDoc.CreateElementNS(AtomProtocolVersion.V10DraftBlogger.NamespaceUri, "atom:title"); //newTitleEl.SetAttribute("type", "text"); //newTitleEl.InnerText = albumName; //newEntryEl.AppendChild(newTitleEl); //var newSummaryEl = newDoc.CreateElementNS(AtomProtocolVersion.V10DraftBlogger.NamespaceUri, "atom:summary"); //newSummaryEl.SetAttribute("type", "text"); //newSummaryEl.InnerText = "This album is used to store pictures from blog posts published by Net Writer."; //newEntryEl.AppendChild(newSummaryEl); //var newAccessEl = newDoc.CreateElementNS(GPHOTO_NS_URI, "gphoto:access"); //newAccessEl.InnerText = "private"; //newEntryEl.AppendChild(newAccessEl); //var newCategoryEl = newDoc.CreateElementNS(AtomProtocolVersion.V10DraftBlogger.NamespaceUri, "atom:category"); //newCategoryEl.SetAttribute("scheme", "http://schemas.google.com/g/2005#kind"); //newCategoryEl.SetAttribute("term", "http://schemas.google.com/photos/2007#album"); //newEntryEl.AppendChild(newCategoryEl); //XmlRestRequestHelper.XmlRequestResult result = new XmlRestRequestHelper.XmlRequestResult() {uri = picasaUri}; //var newAlbumResult = await AtomClient.xmlRestRequestHelper.Post(await CreateAuthorizationFilter(), "application/atom+xml", newDoc, null, result); //var newAlbumResultEntryEl = newAlbumResult.SelectSingleNodeNS("/atom:entry", _nsMgr.ToNSMethodFormat()); //Debug.Assert(newAlbumResultEntryEl != null); //return AtomEntry.GetLink(newAlbumResultEntryEl, _nsMgr, FEED_REL, "application/atom+xml", null, result.uri); }
/// <summary> /// Take the blog post data and put it into the XML node. /// </summary> protected virtual void Populate(BlogPost post, Uri documentUri, XmlElement node, bool publish) { AtomEntry atomEntry = new AtomEntry(_atomVer, _atomNS, CategoryScheme, _nsMgr, documentUri, node); if (post.IsNew) { atomEntry.GenerateId(); } atomEntry.Title = post.Title; if (Options.SupportsExcerpt && post.Excerpt != null && post.Excerpt.Length > 0) { atomEntry.Excerpt = post.Excerpt; } // extra space is to work around AOL Journals XML parsing bug atomEntry.ContentHtml = post.Contents + " "; if (Options.SupportsCustomDate && post.HasDatePublishedOverride) { atomEntry.PublishDate = post.DatePublishedOverride; } if (Options.SupportsCategories) { atomEntry.ClearCategories(); foreach (BlogPostCategory cat in post.Categories) { if (!BlogPostCategoryNone.IsCategoryNone(cat)) { atomEntry.AddCategory(cat); } } if (Options.SupportsNewCategories) { foreach (BlogPostCategory cat in post.NewCategories) { if (!BlogPostCategoryNone.IsCategoryNone(cat)) { atomEntry.AddCategory(cat); } } } } if (Options.SupportsPostAsDraft) { // remove existing draft nodes while (true) { XmlNode draftNode = node.SelectSingleNode(@"app:control/app:draft", _nsMgr); if (draftNode == null) { break; } draftNode.ParentNode.RemoveChild(draftNode); } if (!publish) { // ensure control node exists XmlNode controlNode = node.SelectSingleNode(@"app:control", _nsMgr); if (controlNode == null) { controlNode = node.OwnerDocument.CreateElement(_pubNS.Prefix, "control", _pubNS.Uri); node.AppendChild(controlNode); } // create new draft node XmlElement newDraftNode = node.OwnerDocument.CreateElement(_pubNS.Prefix, "draft", _pubNS.Uri); newDraftNode.InnerText = "yes"; controlNode.AppendChild(newDraftNode); } } //post.Categories; //post.CommentPolicy; //post.CopyFrom; //post.Excerpt; //post.HasDatePublishedOverride; //post.Id; //post.IsNew; //post.IsTemporary; //post.Keywords; //post.Link; //post.Permalink; //post.PingUrls; //post.ResetToNewPost; //post.TrackbackPolicy; }
/// <summary> /// Take the blog post data and put it into the XML node. /// </summary> protected virtual void Populate(BlogPost post, Uri documentUri, XmlElement node, bool publish) { AtomEntry atomEntry = new AtomEntry(_atomVer, _atomNS, CategoryScheme, _nsMgr, documentUri, node); if (post.IsNew) atomEntry.GenerateId(); atomEntry.Title = post.Title; if (Options.SupportsExcerpt && post.Excerpt != null && post.Excerpt.Length > 0) atomEntry.Excerpt = post.Excerpt; // extra space is to work around AOL Journals XML parsing bug atomEntry.ContentHtml = post.Contents + " "; if (Options.SupportsCustomDate && post.HasDatePublishedOverride) { atomEntry.PublishDate = post.DatePublishedOverride; } if (Options.SupportsCategories) { atomEntry.ClearCategories(); foreach (BlogPostCategory cat in post.Categories) if (!BlogPostCategoryNone.IsCategoryNone(cat)) atomEntry.AddCategory(cat); if (Options.SupportsNewCategories) foreach (BlogPostCategory cat in post.NewCategories) if (!BlogPostCategoryNone.IsCategoryNone(cat)) atomEntry.AddCategory(cat); } if (Options.SupportsPostAsDraft) { // remove existing draft nodes while (true) { XmlNode draftNode = node.SelectSingleNode(@"app:control/app:draft", _nsMgr); if (draftNode == null) break; draftNode.ParentNode.RemoveChild(draftNode); } if (!publish) { // ensure control node exists XmlNode controlNode = node.SelectSingleNode(@"app:control", _nsMgr); if (controlNode == null) { controlNode = node.OwnerDocument.CreateElement(_pubNS.Prefix, "control", _pubNS.Uri); node.AppendChild(controlNode); } // create new draft node XmlElement newDraftNode = node.OwnerDocument.CreateElement(_pubNS.Prefix, "draft", _pubNS.Uri); newDraftNode.InnerText = "yes"; controlNode.AppendChild(newDraftNode); } } //post.Categories; //post.CommentPolicy; //post.CopyFrom; //post.Excerpt; //post.HasDatePublishedOverride; //post.Id; //post.IsNew; //post.IsTemporary; //post.Keywords; //post.Link; //post.Permalink; //post.PingUrls; //post.ResetToNewPost; //post.TrackbackPolicy; }
public virtual BlogPost Parse(XmlElement entryNode, bool includeCategories, Uri documentUri) { BlogPost post = new BlogPost(); AtomEntry atomEntry = new AtomEntry(_atomVer, _atomNS, CategoryScheme, _nsMgr, documentUri, entryNode); post.Title = atomEntry.Title; post.Excerpt = atomEntry.Excerpt; post.Id = PostUriToPostId(atomEntry.EditUri); post.Permalink = atomEntry.Permalink; post.Contents = atomEntry.ContentHtml; post.DatePublished = atomEntry.PublishDate; if (Options.SupportsCategories && includeCategories) post.Categories = atomEntry.Categories; return post; }