/// <summary> /// Add a comment to a photo /// </summary> /// <param name="photoID"></param> /// <param name="albumID"></param> /// <param name="access_token"></param> /// <param name="cep"></param> /// <returns></returns> public bool AddCommentToPhoto(string photoID, string albumID, string access_token, Picasa.CommentEntryPost cep) { //POST https://picasaweb.google.com/data/feed/api/user/default/albumid/albumID/photoid/photoID string insertURI = string.Format("{0}{1}{2}" , GoogleUtilityConstants.PICASA_FEED_BASE_URI_NO_HTTPS , GetAlbumURI(albumID) , GetPhotoURI(photoID)); GoogleTCPRequestor tcpr = new GoogleTCPRequestor(Requestor.Operation.POST , Requestor.HTTPFormat.FORMAT_1_1 , Requestor.ContentType.ATOM_XML , GoogleUtilityConstants.GOOGLE_PICASA_HOST , insertURI , cep.toXmlPostString() , access_token , true); //submit the request: return tcpr.SubmitRequest(true, false, Requestor.ResponseTerminatorAction.CONTAINS_HTTP_1_1_201_CREATED); }
/// <summary> /// Create an album and return the ID for the album. /// </summary> /// <param name="aep">The album entry xml to post</param> /// <param name="access_token">The user accss token</param> /// <returns></returns> public string CreateAlbum(Picasa.AlbumEntryPost aep, string access_token) { GoogleTCPRequestor tcpr = new GoogleTCPRequestor(Requestor.Operation.POST , Requestor.HTTPFormat.FORMAT_1_1 , Requestor.ContentType.ATOM_XML , GoogleUtilityConstants.GOOGLE_PICASA_HOST , GoogleUtilityConstants.PICASA_FEED_BASE_URI_NO_HTTPS , aep.toXmlPostString() , access_token , true); string response = tcpr.SubmitRequest(true, Requestor.ResponseTerminatorAction.READ_TO_END); string match1 = "<gphoto:id>"; string match2 = "</gphoto:id>"; string albumID = response.Substring(response.IndexOf(match1), response.IndexOf(match2) - response.IndexOf(match1)); albumID = albumID.Replace(match1, ""); albumID = albumID.Replace("<", ""); albumID = albumID.Replace("/", ""); return albumID; }
/// <summary> /// Post a photo /// </summary> /// <param name="p">The Photo Entry information to post</param> /// <param name="albumID">The album to post to</param> /// <param name="access_token">The user access token</param> /// <returns></returns> public string PostPhoto(Picasa.PhotoEntryPost p, string albumID, string access_token) { FileInfo fi = new FileInfo(p.fileName); Requestor.ContentType contentType = Requestor.ContentType.IMAGE_JPG; switch (fi.Extension) { case ".jpg": contentType = Requestor.ContentType.IMAGE_JPG; break; case ".bmp": contentType = Requestor.ContentType.IMAGE_BMP; break; case ".png": contentType = Requestor.ContentType.IMAGE_PNG; break; case ".gif": contentType = Requestor.ContentType.IMAGE_GIF; break; } GoogleTCPRequestor tcpr = new GoogleTCPRequestor(Requestor.Operation.POST , Requestor.HTTPFormat.FORMAT_1_1 , contentType , GoogleUtilityConstants.GOOGLE_PICASA_HOST , string.Format("{0}{1}" , GoogleUtilityConstants.PICASA_FEED_BASE_URI_NO_HTTPS , string.Format(GoogleUtilityConstants.PICASA_ALBUMID_URI, albumID)) , p.toXmlPostString() , access_token , true); string response = tcpr.SubmitAltRequest(true, Requestor.ResponseTerminatorAction.ENTRY_TERMINATOR, p.payload, contentType); SyndicationItem si = getItemFromResponse(response); string retString = ""; if (si != null) { foreach (var link in si.Links) { Picasa.Link l = new Picasa.Link(); l.Type = link.MediaType; l.Rel = link.RelationshipType; l.HREF = link.Uri.AbsoluteUri; if (l.Rel.ToLower().Contains("feed")) { retString = l.HREF; } System.Diagnostics.Debug.WriteLine(l.HREF); } } return retString; }
/// <summary> /// Post the photo tag /// </summary> /// <param name="albumID"></param> /// <param name="photoID"></param> /// <param name="tep"></param> /// <param name="access_token"></param> /// <returns></returns> private bool PostTagToPhoto(string albumID, string photoID, Picasa.TagEntryPost tep, string access_token) { string updateURI = string.Format("{0}{1}{2}" , GoogleUtilityConstants.PICASA_FEED_BASE_URI_NO_HTTPS , GetAlbumURI(albumID) , GetPhotoURI(photoID)); GoogleTCPRequestor tcpr = new GoogleTCPRequestor(Requestor.Operation.POST , Requestor.HTTPFormat.FORMAT_1_1 , Requestor.ContentType.ATOM_XML , GoogleUtilityConstants.GOOGLE_PICASA_HOST , updateURI , tep.toXmlPostString() , access_token , true); //submit the request: return tcpr.SubmitRequest(true, false, Requestor.ResponseTerminatorAction.CONTAINS_HTTP_1_1_201_CREATED); }