/// <summary> /// Constructs a collection of Flickr photographs. The collection is a result /// of the passed in method, and numPerPage represents how many should be /// fetched at a time. /// </summary> /// <param name="numPerPage"></param> internal FlickrPhotos(FlickrMethod photoQuery, int numPerPage) { _photoQueryMethod = photoQuery; _photoListCache = new Dictionary<int, List<FlickrPhoto>>(); _numPerPage = numPerPage; _count = Int32.MaxValue; _user = null; }
internal FlickrPhotos(FlickrMethod method, int numPerPage, AuthorizedFlickrUser user) : this(method, numPerPage) { _user = user; }
/// <summary> /// Gets the authorization info a logged in user /// </summary> /// <param name="frob"></param> /// <returns></returns> private static AuthorizedFlickrUser GetAuthorizationInfo(string frob) { AuthorizedFlickrUser flickrUser = null; FlickrMethod method = new FlickrMethod(ApiKey, "flickr.auth.getToken"); method.AddParameter("frob", frob); XmlNode rspNode = null; if (method.MakeSignedRequest(SharedSecret, out rspNode)) { foreach (XmlNode outputArg in rspNode.ChildNodes) { if (outputArg.Name == "auth") { flickrUser = ParseAuthorizationInfo(outputArg.ChildNodes); } } } authorizedUser = flickrUser; return flickrUser; }
/// <summary> /// Gets a frob from the Flickr service /// </summary> /// <returns></returns> private static string GetFrob() { FlickrMethod method = new FlickrMethod(ApiKey, "flickr.auth.getFrob"); XmlNode rspNode = null; if (method.MakeSignedRequest(SharedSecret, out rspNode)) { foreach (XmlNode outputArg in rspNode.ChildNodes) { if (outputArg.Name == "frob") { return outputArg.InnerText; } } } throw new Exception("Error getting frob"); }
/// <summary> /// Searches for photos in the given latitude/longitude range. /// </summary> /// <param name="latLong"></param> /// <returns></returns> public static FlickrPhotos SearchForPhotos(Rect latLong) { FlickrMethod method = new FlickrMethod(ApiKey, "flickr.photos.search"); method.AddParameter("accuracy", "1"); method.AddParameter("extras", "geo"); string searchString = latLong.Left + "," + latLong.Top + "," + latLong.Right + "," + latLong.Bottom; method.AddParameter("bbox", searchString); FlickrPhotos photos = new FlickrPhotos(method, 50); photos.GetPhoto(0); // we call this to force the call to get the total # count return photos; }
/// <summary> /// Gets the photos returned from the given flickr method /// </summary> /// <param name="method"></param> /// <param name="totalPhotos"></param> /// <returns></returns> internal static List<FlickrPhoto> GetPhotos(FlickrMethod method, ref int totalPhotos) { XmlNode rspNode = null; List<FlickrPhoto> photos = new List<FlickrPhoto>(); DateTime time = DateTime.Now; if (method.MakeRequest(out rspNode)) { foreach (XmlNode outputArg in rspNode.ChildNodes) { if (outputArg.Name == "photos") { totalPhotos = Int32.Parse(outputArg.Attributes["total"].InnerText); foreach (XmlNode photoNode in outputArg.ChildNodes) { photos.Add(new FlickrPhoto(photoNode.Attributes["id"].InnerText, photoNode.Attributes["server"].InnerText, photoNode.Attributes["secret"].InnerText, method.AuthToken)); } } } } return photos; }
/// <summary> /// Searches for photos based upon the given query string /// </summary> /// <param name="query"></param> /// <returns></returns> public static FlickrPhotos SearchForPhotos(string query) { FlickrMethod method = new FlickrMethod(ApiKey, "flickr.photos.search"); method.AddParameter("text", query); method.AddParameter("sort", "relevance"); FlickrPhotos photos = new FlickrPhotos(method, 50); photos.GetPhoto(0); // we call this to force the call to get the total # count return photos; }
/// <summary> /// Posts the given comments about the given photo. /// </summary> /// <param name="comments"></param> /// <param name="photo"></param> /// <param name="user"></param> /// <returns></returns> public static bool PostComments(string comments, FlickrPhoto photo, AuthorizedFlickrUser user) { FlickrMethod method = new FlickrMethod(ApiKey, "flickr.photos.comments.addComment", user.Token, SharedSecret); method.AddParameter("comment_text", comments); method.AddParameter("photo_id", photo.ID); XmlNode rspNode = null; return method.MakeRequest(out rspNode); }
/// <summary> /// Gets the info about the given user /// </summary> /// <param name="userid"></param> /// <returns></returns> public static XmlNode GetUserInfo(string userid) { FlickrMethod method = new FlickrMethod(ApiKey, "flickr.people.getInfo"); method.AddParameter("user_id", userid); XmlNode rspNode = null; if (method.MakeRequest(out rspNode)) { return rspNode.ChildNodes[0]; } return null; }
/// <summary> /// Gets the list of a users most recently updated photos /// </summary> /// <param name="user"></param> /// <returns></returns> public static FlickrPhotos GetRecentlyUpdated(AuthorizedFlickrUser user) { FlickrMethod method = new FlickrMethod(ApiKey, "flickr.photos.recentlyUpdated", user.Token, SharedSecret); int updateTime = 1; method.AddParameter("min_date", updateTime.ToString()); FlickrPhotos photos = new FlickrPhotos(method, 50, user); photos.GetPhoto(0); // we call this to force the call to get the total # count return photos; }
/// <summary> /// Gets the location of the given photo /// </summary> /// <param name="photo"></param> /// <returns></returns> public static string GetPhotoLocation(FlickrPhoto photo) { FlickrMethod method; if (photo.AuthToken != null) { method = new FlickrMethod(ApiKey, "flickr.photos.geo.getLocation", photo.AuthToken, SharedSecret); } else { method = new FlickrMethod(ApiKey, "flickr.photos.geo.getLocation"); } method.AddParameter("photo_id", photo.ID); XmlNode rspNode = null; if (method.MakeRequest(out rspNode)) { return rspNode.InnerXml; } return ""; }