using System; using System.Net; using System.IO; using System.Xml; using System.Xml.XPath; using System.Xml.Serialization; using System.Text; using System.Collections; using System.Collections.Specialized; namespace FlickrNet { /// /// The main Flickr class. /// /// /// Create an instance of this class and then call its methods to perform methods on Flickr. /// /// /// FlickrNet.Flickr flickr = new FlickrNet.Flickr(); /// User user = flickr.PeopleFindByEmail("cal@iamcal.com"); /// Console.WriteLine("User Id is " + u.UserId); /// //[System.Net.WebPermission(System.Security.Permissions.SecurityAction.Demand, ConnectPattern="http://www.flickr.com/.*")] public class Flickr { #region [ Upload Event and Delegate ] /// /// /// public delegate void UploadProgressHandler(object sender, UploadProgressEventArgs e); /// /// UploadProgressHandler is fired during a synchronous upload process to signify that /// a segment of uploading has been completed. This is approximately 50 bytes. The total /// uploaded is recorded in the class. /// public event UploadProgressHandler OnUploadProgress; #endregion #region [ Private Variables ] private static bool _isServiceSet = false; private static SupportedService _defaultService = SupportedService.Flickr; private SupportedService _service = SupportedService.Flickr; private string BaseUrl { get { return _baseUrl[(int)_service]; } } private string[] _baseUrl = new string[] { "http://api.flickr.com/services/rest/", "http://beta.zooomr.com/bluenote/api/rest", "http://www.23hq.com/services/rest/"}; private string UploadUrl { get { return _uploadUrl[(int)_service]; } } private static string[] _uploadUrl = new string[] { "http://api.flickr.com/services/upload/", "http://beta.zooomr.com/bluenote/api/upload", "http://www.23hq.com/services/upload/"}; private string ReplaceUrl { get { return _replaceUrl[(int)_service]; } } private static string[] _replaceUrl = new string[] { "http://api.flickr.com/services/replace/", "http://beta.zooomr.com/bluenote/api/replace", "http://www.23hq.com/services/replace/"}; private string AuthUrl { get { return _authUrl[(int)_service]; } } private static string[] _authUrl = new string[] { "http://www.flickr.com/services/auth/", "http://beta.zooomr.com/auth/", "http://www.23hq.com/services/auth/"}; private string _apiKey; private string _apiToken; private string _sharedSecret; private int _timeout = 30000; private const string UserAgent = "Mozilla/4.0 FlickrNet API (compatible; MSIE 6.0; Windows NT 5.1)"; private string _lastRequest; private string _lastResponse; private WebProxy _proxy;// = WebProxy.GetDefaultProxy(); // Static serializers private static XmlSerializer _responseSerializer = new XmlSerializer(typeof(FlickrNet.Response)); private static XmlSerializer _uploaderSerializer = new XmlSerializer(typeof(FlickrNet.Uploader)); #endregion #region [ Public Properties ] /// /// Get or set the API Key to be used by all calls. API key is mandatory for all /// calls to Flickr. /// public string ApiKey { get { return _apiKey; } set { _apiKey = (value==null||value.Length==0?null:value); } } /// /// API shared secret is required for all calls that require signing, which includes /// all methods that require authentication, as well as the actual flickr.auth.* calls. /// public string ApiSecret { get { return _sharedSecret; } set { _sharedSecret = (value==null||value.Length==0?null:value); } } /// /// The API token is required for all calls that require authentication. /// A will be raised by Flickr if the API token is /// not set when required. /// /// /// It should be noted that some methods will work without the API token, but /// will return different results if used with them (such as group pool requests, /// and results which include private pictures the authenticated user is allowed to see /// (their own, or others). /// [Obsolete("Renamed to AuthToken to be more consistent with the Flickr API")] public string ApiToken { get { return _apiToken; } set { _apiToken = (value==null||value.Length==0?null:value); } } /// /// The authentication token is required for all calls that require authentication. /// A will be raised by Flickr if the authentication token is /// not set when required. /// /// /// It should be noted that some methods will work without the authentication token, but /// will return different results if used with them (such as group pool requests, /// and results which include private pictures the authenticated user is allowed to see /// (their own, or others). /// public string AuthToken { get { return _apiToken; } set { _apiToken = (value==null||value.Length==0?null:value); } } /// /// Gets or sets whether the cache should be disabled. Use only in extreme cases where you are sure you /// don't want any caching. /// public static bool CacheDisabled { get { return Cache.CacheDisabled; } set { Cache.CacheDisabled = value; } } /// /// All GET calls to Flickr are cached by the Flickr.Net API. Set the /// to determine how long these calls should be cached (make this as long as possible!) /// public static TimeSpan CacheTimeout { get { return Cache.CacheTimeout; } set { Cache.CacheTimeout = value; } } /// /// Sets or gets the location to store the Cache files. /// public static string CacheLocation { get { return Cache.CacheLocation; } set { Cache.CacheLocation = value; } } /// /// Gets the current size of the Cache. /// public static long CacheSize { get { return Cache.CacheSize; } } /// /// is the cache file size in bytes for downloaded /// pictures. The default is 50MB (or 50 * 1024 * 1025 in bytes). /// public static long CacheSizeLimit { get { return Cache.CacheSizeLimit; } set { Cache.CacheSizeLimit = value; } } /// /// The default service to use for new Flickr instances /// public static SupportedService DefaultService { get { if( !_isServiceSet && FlickrConfigurationManager.Settings != null ) { _defaultService = FlickrConfigurationManager.Settings.Service; _isServiceSet = true; } return _defaultService; } set { _defaultService = value; _isServiceSet = true; } } /// /// The current service that the Flickr API is using. /// public SupportedService CurrentService { get { return _service; } set { _service = value; } } /// /// Internal timeout for all web requests in milliseconds. Defaults to 30 seconds. /// public int HttpTimeout { get { return _timeout; } set { _timeout = value; } } /// /// Checks to see if a shared secret and an api token are stored in the object. /// Does not check if these values are valid values. /// public bool IsAuthenticated { get { return (_sharedSecret != null && _apiToken != null); } } /// /// Returns the raw XML returned from the last response. /// Only set it the response was not returned from cache. /// public string LastResponse { get { return _lastResponse; } } /// /// Returns the last URL requested. Includes API signing. /// public string LastRequest { get { return _lastRequest; } } /// /// You can set the or alter its properties. /// It defaults to your internet explorer proxy settings. /// public WebProxy Proxy { get { return _proxy; } set { _proxy = value; } } #endregion #region [ Cache Methods ] /// /// Clears the cache completely. /// public static void FlushCache() { Cache.FlushCache(); } /// /// Clears the cache for a particular URL. /// /// The URL to remove from the cache. /// /// The URL can either be an image URL for a downloaded picture, or /// a request URL (see for getting the last URL). /// public static void FlushCache(string url) { Cache.FlushCache(url); } /// /// Provides static access to the list of cached photos. /// /// An array of objects. public static PictureCacheItem[] GetCachePictures() { return (PictureCacheItem[]) Cache.Downloads.ToArray(typeof(PictureCacheItem)); } #endregion #region [ Constructors ] /// /// Constructor loads configuration settings from app.config or web.config file if they exist. /// public Flickr() { FlickrConfigurationSettings settings = FlickrConfigurationManager.Settings; if( settings == null ) return; if( settings.CacheSize != 0 ) CacheSizeLimit = settings.CacheSize; if( settings.CacheTimeout != TimeSpan.MinValue ) CacheTimeout = settings.CacheTimeout; ApiKey = settings.ApiKey; AuthToken = settings.ApiToken; ApiSecret = settings.SharedSecret; CurrentService = DefaultService; if( settings.IsProxyDefined ) { Proxy = new WebProxy(); Proxy.Address = new Uri("http://" + settings.ProxyIPAddress + ":" + settings.ProxyPort); if( settings.ProxyUsername != null && settings.ProxyUsername.Length > 0 ) { NetworkCredential creds = new NetworkCredential(); creds.UserName = settings.ProxyUsername; creds.Password = settings.ProxyPassword; creds.Domain = settings.ProxyDomain; Proxy.Credentials = creds; } } else { // try and get default IE settings try { Proxy = WebProxy.GetDefaultProxy(); } catch(System.Security.SecurityException) { // Capture SecurityException for when running in a Medium Trust environment. } } } /// /// Create a new instance of the class with no authentication. /// /// Your Flickr API Key. public Flickr(string apiKey) : this(apiKey, "", "") { } /// /// Creates a new instance of the class with an API key and a Shared Secret. /// This is only useful really useful for calling the Auth functions as all other /// authenticationed methods also require the API Token. /// /// Your Flickr API Key. /// Your Flickr Shared Secret. public Flickr(string apiKey, string sharedSecret) : this(apiKey, sharedSecret, "") { } /// /// Create a new instance of the class with the email address and password given /// /// Your Flickr API Key /// Your FLickr Shared Secret. /// The token for the user who has been authenticated. public Flickr(string apiKey, string sharedSecret, string token) : this() { _apiKey = apiKey; _sharedSecret = sharedSecret; _apiToken = token; } #endregion #region [ Private Methods ] /// /// A private method which performs the actual HTTP web request if /// the details are not found within the cache. /// /// The URL to download. /// A object. private string DoGetResponse(string url) { HttpWebRequest req = null; HttpWebResponse res = null; // Initialise the web request req = (HttpWebRequest)HttpWebRequest.Create(url); req.Method = CurrentService==SupportedService.Zooomr?"GET":"POST"; if( req.Method == "POST" ) req.ContentLength = 0; //req.Method = "POST"; req.UserAgent = UserAgent; if( Proxy != null ) req.Proxy = Proxy; req.Timeout = HttpTimeout; req.KeepAlive = false; try { // Get response from the internet res = (HttpWebResponse)req.GetResponse(); } catch(WebException ex) { if( ex.Status == WebExceptionStatus.ProtocolError ) { HttpWebResponse res2 = (HttpWebResponse)ex.Response; if( res2 != null ) { throw new FlickrException((int)res2.StatusCode, res2.StatusDescription); } } throw new FlickrException(9999, ex.Message); } string responseString = string.Empty; using (StreamReader sr = new StreamReader(res.GetResponseStream())) { responseString = sr.ReadToEnd(); } return responseString; } /// /// Download a picture (or anything else actually). /// /// /// private Stream DoDownloadPicture(string url) { HttpWebRequest req = null; HttpWebResponse res = null; try { req = (HttpWebRequest)HttpWebRequest.Create(url); req.UserAgent = UserAgent; if( Proxy != null ) req.Proxy = Proxy; req.Timeout = HttpTimeout; req.KeepAlive = false; res = (HttpWebResponse)req.GetResponse(); } catch(WebException ex) { if( ex.Status == WebExceptionStatus.ProtocolError ) { HttpWebResponse res2 = (HttpWebResponse)ex.Response; if( res2 != null ) { throw new FlickrException((int)res2.StatusCode, res2.StatusDescription); } } else if( ex.Status == WebExceptionStatus.Timeout ) { throw new FlickrException(301, "Request time-out"); } throw new FlickrException(9999, "Picture download failed (" + ex.Message + ")"); } return res.GetResponseStream(); } #endregion #region [ GetResponse methods ] private Response GetResponseNoCache(Hashtable parameters) { return GetResponse(parameters, TimeSpan.MinValue); } private Response GetResponseAlwaysCache(Hashtable parameters) { return GetResponse(parameters, TimeSpan.MaxValue); } private Response GetResponseCache(Hashtable parameters) { return GetResponse(parameters, Cache.CacheTimeout); } private Response GetResponse(Hashtable parameters, TimeSpan cacheTimeout) { // Calulate URL StringBuilder UrlStringBuilder = new StringBuilder(BaseUrl, 2 * 1024); StringBuilder HashStringBuilder = new StringBuilder(_sharedSecret, 2 * 1024); UrlStringBuilder.Append("?"); parameters["api_key"] = _apiKey; if( _apiToken != null && _apiToken.Length > 0 ) { parameters["auth_token"] = _apiToken; } string[] keys = new string[parameters.Keys.Count]; parameters.Keys.CopyTo(keys, 0); Array.Sort(keys); foreach(string key in keys) { if( UrlStringBuilder.Length > BaseUrl.Length + 1 ) UrlStringBuilder.Append("&"); UrlStringBuilder.Append(key); UrlStringBuilder.Append("="); UrlStringBuilder.Append(Utils.UrlEncode((string)parameters[key])); HashStringBuilder.Append(key); HashStringBuilder.Append(parameters[key]); } if (_sharedSecret != null && _sharedSecret.Length > 0) { if (UrlStringBuilder.Length > BaseUrl.Length + 1) { UrlStringBuilder.Append("&"); } UrlStringBuilder.Append("api_sig="); UrlStringBuilder.Append(Md5Hash(HashStringBuilder.ToString())); } string url = UrlStringBuilder.ToString(); _lastRequest = url; _lastResponse = string.Empty; if( CacheDisabled ) { string responseXml = DoGetResponse(url); _lastResponse = responseXml; return Deserialize(responseXml); } else { ResponseCacheItem cached = (ResponseCacheItem) Cache.Responses.Get(url, cacheTimeout, true); if (cached != null) { System.Diagnostics.Debug.WriteLine("Cache hit"); _lastResponse = cached.Response; return Deserialize(cached.Response); } else { System.Diagnostics.Debug.WriteLine("Cache miss"); string responseXml = DoGetResponse(url); _lastResponse = responseXml; ResponseCacheItem resCache = new ResponseCacheItem(); resCache.Response = responseXml; resCache.Url = url; resCache.CreationTime = DateTime.UtcNow; FlickrNet.Response response = Deserialize(responseXml); if( response.Status == ResponseStatus.OK ) { Cache.Responses.Shrink(Math.Max(0, Cache.CacheSizeLimit - responseXml.Length)); Cache.Responses[url] = resCache; } return response; } } } /// /// Converts the response string (in XML) into the object. /// /// The response from Flickr. /// A object containing the details of the private static Response Deserialize(string responseString) { XmlSerializer serializer = _responseSerializer; try { // Deserialise the web response into the Flickr response object StringReader responseReader = new StringReader(responseString); FlickrNet.Response response = (FlickrNet.Response)serializer.Deserialize(responseReader); responseReader.Close(); return response; } catch(InvalidOperationException ex) { // Serialization error occurred! throw new FlickrException(9998, "Invalid response received (" + ex.Message + ")"); } } #endregion #region [ DownloadPicture ] /// /// Downloads the picture from a internet and transfers it to a stream object. /// /// The url of the image to download. /// A object containing the downloaded picture. /// /// The method checks the download cache first to see if the picture has already /// been downloaded and if so returns the cached image. Otherwise it goes to the internet for the actual /// image. /// public System.IO.Stream DownloadPicture(string url) { const int BUFFER_SIZE = 1024 * 10; PictureCacheItem cacheItem = (PictureCacheItem) Cache.Downloads[url]; if (cacheItem != null) { return new FileStream(cacheItem.filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); } PictureCacheItem picCache = new PictureCacheItem(); picCache.filename = Path.Combine(Cache.CacheLocation,Guid.NewGuid().ToString()); Stream read = DoDownloadPicture(url); Stream write = new FileStream(picCache.filename, FileMode.Create, FileAccess.Write, FileShare.None); byte[] buffer = new byte[BUFFER_SIZE]; int bytes = 0; long fileSize = 0; while( (bytes = read.Read(buffer, 0, BUFFER_SIZE)) > 0 ) { fileSize += bytes; write.Write(buffer, 0, bytes); } read.Close(); write.Close(); picCache.url = url; picCache.creationTime = DateTime.UtcNow; picCache.fileSize = fileSize; Cache.Downloads.Shrink(Math.Max(0, Cache.CacheSizeLimit - fileSize)); Cache.Downloads[url] = picCache; return new FileStream(picCache.filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); } #endregion #region [ Auth ] /// /// Retrieve a temporary FROB from the Flickr service, to be used in redirecting the /// user to the Flickr web site for authentication. Only required for desktop authentication. /// /// /// Pass the FROB to the method to calculate the url. /// /// /// /// string frob = flickr.AuthGetFrob(); /// string url = flickr.AuthCalcUrl(frob, AuthLevel.Read); /// /// // redirect the user to the url above and then wait till they have authenticated and return to the app. /// /// Auth auth = flickr.AuthGetToken(frob); /// /// // then store the auth.Token for later use. /// string token = auth.Token; /// /// /// The FROB. public string AuthGetFrob() { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.auth.getFrob"); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.AllElements[0].InnerText; } else { throw new FlickrException(response.Error); } } /// /// Calculates the URL to redirect the user to Flickr web site for /// authentication. Used by desktop application. /// See for example code. /// /// The FROB to be used for authentication. /// The stating the maximum authentication level your application requires. /// The url to redirect the user to. public string AuthCalcUrl(string frob, AuthLevel authLevel) { if( _sharedSecret == null ) throw new FlickrException(0, "AuthGetToken requires signing. Please supply api key and secret."); string hash = _sharedSecret + "api_key" + _apiKey + "frob" + frob + "perms" + authLevel.ToString().ToLower(); hash = Md5Hash(hash); string url = AuthUrl + "?api_key=" + _apiKey + "&perms=" + authLevel.ToString().ToLower() + "&frob=" + frob; url += "&api_sig=" + hash; return url; } /// /// Calculates the URL to redirect the user to Flickr web site for /// auehtntication. Used by Web applications. /// See for example code. /// /// /// The Flickr web site provides 'tiny urls' that can be used in place /// of this URL when you specify your return url in the API key page. /// It is recommended that you use these instead as they do not include /// your API or shared secret. /// /// The stating the maximum authentication level your application requires. /// The url to redirect the user to. public string AuthCalcWebUrl(AuthLevel authLevel) { if( _sharedSecret == null ) throw new FlickrException(0, "AuthGetToken requires signing. Please supply api key and secret."); string hash = _sharedSecret + "api_key" + _apiKey + "perms" + authLevel.ToString().ToLower(); hash = Md5Hash(hash); string url = AuthUrl + "?api_key=" + _apiKey + "&perms=" + authLevel.ToString().ToLower(); url += "&api_sig=" + hash; return url; } /// /// After the user has authenticated your application on the flickr web site call this /// method with the FROB (either stored from or returned in the URL /// from the Flickr web site) to get the users token. /// /// The string containing the FROB. /// A object containing user and token details. public Auth AuthGetToken(string frob) { if( _sharedSecret == null ) throw new FlickrException(0, "AuthGetToken requires signing. Please supply api key and secret."); Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.auth.getToken"); parameters.Add("frob", frob); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { Auth auth = new Auth(response.AllElements[0]); return auth; } else { throw new FlickrException(response.Error); } } /// /// Gets the full token details for a given mini token, entered by the user following a /// web based authentication. /// /// The mini token. /// An instance class, detailing the user and their full token. public Auth AuthGetFullToken(string miniToken) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.auth.getFullToken"); parameters.Add("mini_token", miniToken); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { Auth auth = new Auth(response.AllElements[0]); return auth; } else { throw new FlickrException(response.Error); } } /// /// Checks a authentication token with the flickr service to make /// sure it is still valid. /// /// The authentication token to check. /// The object detailing the user for the token. public Auth AuthCheckToken(string token) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.auth.checkToken"); parameters.Add("auth_token", token); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { Auth auth = new Auth(response.AllElements[0]); return auth; } else { throw new FlickrException(response.Error); } } #endregion #region [ UploadPicture ] /// /// Uploads a file to Flickr. /// /// The filename of the file to open. /// The id of the photo on a successful upload. /// Thrown when Flickr returns an error. see http://www.flickr.com/services/api/upload.api.html for more details. /// Other exceptions may be thrown, see constructors for more details. public string UploadPicture(string filename) { return UploadPicture(filename, null, null, null, true, false, false); } /// /// Uploads a file to Flickr. /// /// The filename of the file to open. /// The title of the photograph. /// The id of the photo on a successful upload. /// Thrown when Flickr returns an error. see http://www.flickr.com/services/api/upload.api.html for more details. /// Other exceptions may be thrown, see constructors for more details. public string UploadPicture(string filename, string title) { return UploadPicture(filename, title, null, null, true, false, false); } /// /// Uploads a file to Flickr. /// /// The filename of the file to open. /// The title of the photograph. /// The description of the photograph. /// The id of the photo on a successful upload. /// Thrown when Flickr returns an error. see http://www.flickr.com/services/api/upload.api.html for more details. /// Other exceptions may be thrown, see constructors for more details. public string UploadPicture(string filename, string title, string description) { return UploadPicture(filename, title, description, null, true, false, false); } /// /// Uploads a file to Flickr. /// /// The filename of the file to open. /// The title of the photograph. /// The description of the photograph. /// A comma seperated list of the tags to assign to the photograph. /// The id of the photo on a successful upload. /// Thrown when Flickr returns an error. see http://www.flickr.com/services/api/upload.api.html for more details. /// Other exceptions may be thrown, see constructors for more details. public string UploadPicture(string filename, string title, string description, string tags) { Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); return UploadPicture(stream, title, description, tags, -1, -1, -1); } /// /// Uploads a file to Flickr. /// /// The filename of the file to open. /// The title of the photograph. /// The description of the photograph. /// A comma seperated list of the tags to assign to the photograph. /// True if the photograph should be public and false if it should be private. /// True if the photograph should be marked as viewable by friends contacts. /// True if the photograph should be marked as viewable by family contacts. /// The id of the photo on a successful upload. /// Thrown when Flickr returns an error. see http://www.flickr.com/services/api/upload.api.html for more details. /// Other exceptions may be thrown, see constructors for more details. public string UploadPicture(string filename, string title, string description, string tags, bool isPublic, bool isFamily, bool isFriend) { Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); return UploadPicture(stream, title, description, tags, isPublic?1:0, isFamily?1:0, isFriend?1:0); } /// /// UploadPicture method that does all the uploading work. /// /// The object containing the pphoto to be uploaded. /// The title of the photo (optional). /// The description of the photograph (optional). /// The tags for the photograph (optional). /// 0 for private, 1 for public. /// 1 if family, 0 is not. /// 1 if friend, 0 if not. /// The id of the photograph after successful uploading. public string UploadPicture(Stream stream, string title, string description, string tags, int isPublic, int isFamily, int isFriend) { /* * * Modified UploadPicture code taken from the Flickr.Net library * URL: http://workspaces.gotdotnet.com/flickrdotnet * It is used under the terms of the Common Public License 1.0 * URL: http://www.opensource.org/licenses/cpl.php * * */ string boundary = "FLICKR_MIME_" + DateTime.Now.ToString("yyyyMMddhhmmss"); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(UploadUrl); req.UserAgent = "Mozilla/4.0 FlickrNet API (compatible; MSIE 6.0; Windows NT 5.1)"; req.Method = "POST"; if( Proxy != null ) req.Proxy = Proxy; //req.Referer = "http://www.flickr.com"; req.KeepAlive = true; req.Timeout = HttpTimeout * 1000; req.ContentType = "multipart/form-data; boundary=" + boundary + ""; req.Expect = ""; StringBuilder sb = new StringBuilder(); Hashtable parameters = new Hashtable(); if( title != null && title.Length > 0 ) { parameters.Add("title", title); } if( description != null && description.Length > 0 ) { parameters.Add("description", description); } if( tags != null && tags.Length > 0 ) { parameters.Add("tags", tags); } if( isPublic >= 0 ) { parameters.Add("is_public", isPublic.ToString()); } if( isFriend >= 0 ) { parameters.Add("is_friend", isFriend.ToString()); } if( isFamily >= 0 ) { parameters.Add("is_family", isFamily.ToString()); } parameters.Add("api_key", _apiKey); parameters.Add("auth_token", _apiToken); string[] keys = new string[parameters.Keys.Count]; parameters.Keys.CopyTo(keys, 0); Array.Sort(keys); StringBuilder HashStringBuilder = new StringBuilder(_sharedSecret, 2 * 1024); foreach(string key in keys) { HashStringBuilder.Append(key); HashStringBuilder.Append(parameters[key]); sb.Append("--" + boundary + "\r\n"); sb.Append("Content-Disposition: form-data; name=\"" + key + "\"\r\n"); sb.Append("\r\n"); sb.Append(parameters[key] + "\r\n"); } sb.Append("--" + boundary + "\r\n"); sb.Append("Content-Disposition: form-data; name=\"api_sig\"\r\n"); sb.Append("\r\n"); sb.Append(Md5Hash(HashStringBuilder.ToString()) + "\r\n"); // Photo sb.Append("--" + boundary + "\r\n"); sb.Append("Content-Disposition: form-data; name=\"photo\"; filename=\"image.jpeg\"\r\n"); sb.Append("Content-Type: image/jpeg\r\n"); sb.Append("\r\n"); UTF8Encoding encoding = new UTF8Encoding(); byte[] postContents = encoding.GetBytes(sb.ToString()); byte[] photoContents = new byte[stream.Length]; stream.Read(photoContents, 0, photoContents.Length); stream.Close(); byte[] postFooter = encoding.GetBytes("\r\n--" + boundary + "--\r\n"); byte[] dataBuffer = new byte[postContents.Length + photoContents.Length + postFooter.Length]; Buffer.BlockCopy(postContents, 0, dataBuffer, 0, postContents.Length); Buffer.BlockCopy(photoContents, 0, dataBuffer, postContents.Length, photoContents.Length); Buffer.BlockCopy(postFooter, 0, dataBuffer, postContents.Length + photoContents.Length, postFooter.Length); req.ContentLength = dataBuffer.Length; Stream resStream = req.GetRequestStream(); int j = 1; int uploadBit = Math.Max(dataBuffer.Length / 100, 50*1024); int uploadSoFar = 0; for(int i = 0; i < dataBuffer.Length; i=i+uploadBit) { int toUpload = Math.Min(uploadBit, dataBuffer.Length - i); uploadSoFar += toUpload; resStream.Write(dataBuffer, i, toUpload); if( (OnUploadProgress != null) && ((j++) % 5 == 0 || uploadSoFar == dataBuffer.Length) ) { OnUploadProgress(this, new UploadProgressEventArgs(i+toUpload, uploadSoFar == dataBuffer.Length)); } } resStream.Close(); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); XmlSerializer serializer = _uploaderSerializer; StreamReader sr = new StreamReader(res.GetResponseStream()); string s= sr.ReadToEnd(); sr.Close(); StringReader str = new StringReader(s); FlickrNet.Uploader uploader = (FlickrNet.Uploader)serializer.Deserialize(str); if( uploader.Status == ResponseStatus.OK ) { return uploader.PhotoId; } else { throw new FlickrException(uploader.Code, uploader.Message); } } /// /// Replace an existing photo on Flickr. /// /// The filename of the photo to upload. /// The ID of the photo to replace. /// The id of the photograph after successful uploading. public string ReplacePicture(string filename, string photoId) { FileStream stream = null; try { stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); return ReplacePicture(stream, photoId); } finally { if( stream != null ) stream.Close(); } } /// /// Replace an existing photo on Flickr. /// /// The object containing the photo to be uploaded. /// The ID of the photo to replace. /// The id of the photograph after successful uploading. public string ReplacePicture(Stream stream, string photoId) { string boundary = "FLICKR_MIME_" + DateTime.Now.ToString("yyyyMMddhhmmss"); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(ReplaceUrl); req.UserAgent = "Mozilla/4.0 FlickrNet API (compatible; MSIE 6.0; Windows NT 5.1)"; req.Method = "POST"; if( Proxy != null ) req.Proxy = Proxy; req.Referer = "http://www.flickr.com"; req.KeepAlive = false; req.Timeout = HttpTimeout * 100; req.ContentType = "multipart/form-data; boundary=" + boundary + ""; StringBuilder sb = new StringBuilder(); Hashtable parameters = new Hashtable(); parameters.Add("photo_id", photoId); parameters.Add("api_key", _apiKey); parameters.Add("auth_token", _apiToken); string[] keys = new string[parameters.Keys.Count]; parameters.Keys.CopyTo(keys, 0); Array.Sort(keys); StringBuilder HashStringBuilder = new StringBuilder(_sharedSecret, 2 * 1024); foreach(string key in keys) { HashStringBuilder.Append(key); HashStringBuilder.Append(parameters[key]); sb.Append("--" + boundary + "\r\n"); sb.Append("Content-Disposition: form-data; name=\"" + key + "\"\r\n"); sb.Append("\r\n"); sb.Append(parameters[key] + "\r\n"); } sb.Append("--" + boundary + "\r\n"); sb.Append("Content-Disposition: form-data; name=\"api_sig\"\r\n"); sb.Append("\r\n"); sb.Append(Md5Hash(HashStringBuilder.ToString()) + "\r\n"); // Photo sb.Append("--" + boundary + "\r\n"); sb.Append("Content-Disposition: form-data; name=\"photo\"; filename=\"image.jpeg\"\r\n"); sb.Append("Content-Type: image/jpeg\r\n"); sb.Append("\r\n"); UTF8Encoding encoding = new UTF8Encoding(); byte[] postContents = encoding.GetBytes(sb.ToString()); byte[] photoContents = new byte[stream.Length]; stream.Read(photoContents, 0, photoContents.Length); stream.Close(); byte[] postFooter = encoding.GetBytes("\r\n--" + boundary + "--\r\n"); byte[] dataBuffer = new byte[postContents.Length + photoContents.Length + postFooter.Length]; Buffer.BlockCopy(postContents, 0, dataBuffer, 0, postContents.Length); Buffer.BlockCopy(photoContents, 0, dataBuffer, postContents.Length, photoContents.Length); Buffer.BlockCopy(postFooter, 0, dataBuffer, postContents.Length + photoContents.Length, postFooter.Length); req.ContentLength = dataBuffer.Length; Stream resStream = req.GetRequestStream(); int j = 1; int uploadBit = Math.Max(dataBuffer.Length / 100, 50*1024); int uploadSoFar = 0; for(int i = 0; i < dataBuffer.Length; i=i+uploadBit) { int toUpload = Math.Min(uploadBit, dataBuffer.Length - i); uploadSoFar += toUpload; resStream.Write(dataBuffer, i, toUpload); if( (OnUploadProgress != null) && ((j++) % 5 == 0 || uploadSoFar == dataBuffer.Length) ) { OnUploadProgress(this, new UploadProgressEventArgs(i+toUpload, uploadSoFar == dataBuffer.Length)); } } resStream.Close(); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); XmlSerializer serializer = _uploaderSerializer; StreamReader sr = new StreamReader(res.GetResponseStream()); string s= sr.ReadToEnd(); sr.Close(); StringReader str = new StringReader(s); FlickrNet.Uploader uploader = (FlickrNet.Uploader)serializer.Deserialize(str); if( uploader.Status == ResponseStatus.OK ) { return uploader.PhotoId; } else { throw new FlickrException(uploader.Code, uploader.Message); } } #endregion #region [ Blogs ] /// /// Gets a list of blogs that have been set up by the user. /// Requires authentication. /// /// A object containing the list of blogs. /// public Blogs BlogGetList() { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.blogs.getList"); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Blogs; } else { throw new FlickrException(response.Error); } } /// /// Posts a photo already uploaded to a blog. /// Requires authentication. /// /// The Id of the blog to post the photo too. /// The Id of the photograph to post. /// The title of the blog post. /// The body of the blog post. /// True if the operation is successful. public bool BlogPostPhoto(string blogId, string photoId, string title, string description) { return BlogPostPhoto(blogId, photoId, title, description, null); } /// /// Posts a photo already uploaded to a blog. /// Requires authentication. /// /// The Id of the blog to post the photo too. /// The Id of the photograph to post. /// The title of the blog post. /// The body of the blog post. /// The password of the blog if it is not already stored in flickr. /// True if the operation is successful. public bool BlogPostPhoto(string blogId, string photoId, string title, string description, string blogPassword) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.blogs.postPhoto"); parameters.Add("blog_id", blogId); parameters.Add("photo_id", photoId); parameters.Add("title", title); parameters.Add("description", description); if( blogPassword != null ) parameters.Add("blog_password", blogPassword); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } #endregion #region [ Contacts ] /// /// Gets a list of contacts for the logged in user. /// Requires authentication. /// /// An instance of the class containing the list of contacts. public Contacts ContactsGetList() { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.contacts.getList"); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Contacts; } else { throw new FlickrException(response.Error); } } /// /// Gets a list of the given users contact, or those that are publically avaiable. /// /// The Id of the user who's contacts you want to return. /// An instance of the class containing the list of contacts. public Contacts ContactsGetPublicList(string userId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.contacts.getPublicList"); parameters.Add("user_id", userId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Contacts; } else { throw new FlickrException(response.Error); } } #endregion #region [ Favorites ] /// /// Adds a photo to the logged in favourites. /// Requires authentication. /// /// The id of the photograph to add. /// True if the operation is successful. public bool FavoritesAdd(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.favorites.add"); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } /// /// Removes a photograph from the logged in users favourites. /// Requires authentication. /// /// The id of the photograph to remove. /// True if the operation is successful. public bool FavoritesRemove(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.favorites.remove"); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } /// /// Get a list of the currently logger in users favourites. /// Requires authentication. /// /// instance containing a collection of objects. public Photos FavoritesGetList() { return FavoritesGetList(null, 0, 0); } /// /// Get a list of the currently logger in users favourites. /// Requires authentication. /// /// Number of photos to include per page. /// The page to download this time. /// instance containing a collection of objects. public Photos FavoritesGetList(int perPage, int page) { return FavoritesGetList(null, perPage, page); } /// /// Get a list of favourites for the specified user. /// /// The user id of the user whose favourites you wish to retrieve. /// instance containing a collection of objects. public Photos FavoritesGetList(string userId) { return FavoritesGetList(userId, 0, 0); } /// /// Get a list of favourites for the specified user. /// /// The user id of the user whose favourites you wish to retrieve. /// Number of photos to include per page. /// The page to download this time. /// instance containing a collection of objects. public Photos FavoritesGetList(string userId, int perPage, int page) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.favorites.getList"); if( userId != null ) parameters.Add("user_id", userId); if( perPage > 0 ) parameters.Add("per_page", perPage.ToString()); if( page > 0 ) parameters.Add("page", page.ToString()); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } /// /// Gets the public favourites for a specified user. /// /// This function difers from in that the user id /// is not optional. /// The is of the user whose favourites you wish to return. /// A object containing a collection of objects. public Photos FavoritesGetPublicList(string userId) { return FavoritesGetPublicList(userId, 0, 0); } /// /// Gets the public favourites for a specified user. /// /// This function difers from in that the user id /// is not optional. /// The is of the user whose favourites you wish to return. /// The number of photos to return per page. /// The specific page to return. /// A object containing a collection of objects. public Photos FavoritesGetPublicList(string userId, int perPage, int page) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.favorites.getPublicList"); parameters.Add("user_id", userId); if( perPage > 0 ) parameters.Add("per_page", perPage.ToString()); if( page > 0 ) parameters.Add("page", page.ToString()); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } #endregion #region [ Groups ] /// /// Returns the top with a list of sub-categories and groups. /// (The top category does not have any groups in it but others may). /// /// A instance. public Category GroupsBrowse() { return GroupsBrowse("0"); } /// /// Returns the specified by the category id with a list of sub-categories and groups. /// /// /// A instance. public Category GroupsBrowse(string catId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.groups.browse"); parameters.Add("cat_id", catId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Category; } else { throw new FlickrException(response.Error); } } /// /// Search the list of groups on Flickr for the text. /// /// The text to search for. /// A list of groups matching the search criteria. public GroupSearchResults GroupsSearch(string text) { return GroupsSearch(text, 0, 0); } /// /// Search the list of groups on Flickr for the text. /// /// The text to search for. /// The page of the results to return. /// A list of groups matching the search criteria. public GroupSearchResults GroupsSearch(string text, int page) { return GroupsSearch(text, page, 0); } /// /// Search the list of groups on Flickr for the text. /// /// The text to search for. /// The page of the results to return. /// The number of groups to list per page. /// A list of groups matching the search criteria. public GroupSearchResults GroupsSearch(string text, int page, int perPage) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.groups.search"); parameters.Add("api_key", _apiKey); parameters.Add("text", text); if( page > 0 ) parameters.Add("page", page.ToString()); if( perPage > 0 ) parameters.Add("per_page", perPage.ToString()); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return new GroupSearchResults(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } /// /// Returns a object containing details about a group. /// /// The id of the group to return. /// The specified by the group id. public GroupFullInfo GroupsGetInfo(string groupId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.groups.getInfo"); parameters.Add("api_key", _apiKey); parameters.Add("group_id", groupId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return new GroupFullInfo(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } #endregion #region [ Group Pool ] /// /// Adds a photo to a pool you have permission to add photos to. /// /// The id of one of your photos to be added. /// The id of a group you are a member of. /// True on a successful addition. public bool GroupPoolAdd(string photoId, string groupId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.groups.pools.add"); parameters.Add("photo_id", photoId); parameters.Add("group_id", groupId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } /// /// Gets the context for a photo from within a group. This provides the /// id and thumbnail url for the next and previous photos in the group. /// /// The Photo ID for the photo you want the context for. /// The group ID for the group you want the context to be relevant to. /// The of the photo in the group. public Context GroupPoolGetContext(string photoId, string groupId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.groups.pools.getContext"); parameters.Add("photo_id", photoId); parameters.Add("group_id", groupId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { Context context = new Context(); context.Count = response.ContextCount.Count; context.NextPhoto = response.ContextNextPhoto; context.PreviousPhoto = response.ContextPrevPhoto; return context; } else { throw new FlickrException(response.Error); } } /// /// Remove a picture from a group. /// /// The id of one of your pictures you wish to remove. /// The id of the group to remove the picture from. /// True if the photo is successfully removed. public bool GroupPoolRemove(string photoId, string groupId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.groups.pools.remove"); parameters.Add("photo_id", photoId); parameters.Add("group_id", groupId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } /// /// Gets a list of /// /// public MemberGroupInfo[] GroupPoolGetGroups() { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.groups.pools.getGroups"); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return MemberGroupInfo.GetMemberGroupInfo(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } /// /// Gets a list of photos for a given group. /// /// The group ID for the group. /// A object containing the list of photos. public Photos GroupPoolGetPhotos(string groupId) { return GroupPoolGetPhotos(groupId, null, null, PhotoSearchExtras.All, 0, 0); } /// /// Gets a list of photos for a given group. /// /// The group ID for the group. /// Space seperated list of tags that photos returned must have. /// A object containing the list of photos. public Photos GroupPoolGetPhotos(string groupId, string tags) { return GroupPoolGetPhotos(groupId, tags, null, PhotoSearchExtras.All, 0, 0); } /// /// Gets a list of photos for a given group. /// /// The group ID for the group. /// The number of photos per page. /// The page to return. /// A object containing the list of photos. public Photos GroupPoolGetPhotos(string groupId, int perPage, int page) { return GroupPoolGetPhotos(groupId, null, null, PhotoSearchExtras.All, perPage, page); } /// /// Gets a list of photos for a given group. /// /// The group ID for the group. /// Space seperated list of tags that photos returned must have. /// The number of photos per page. /// The page to return. /// A object containing the list of photos. public Photos GroupPoolGetPhotos(string groupId, string tags, int perPage, int page) { return GroupPoolGetPhotos(groupId, tags, null, PhotoSearchExtras.All, perPage, page); } /// /// Gets a list of photos for a given group. /// /// The group ID for the group. /// Space seperated list of tags that photos returned must have. /// Currently only supports 1 tag at a time. /// The group member to return photos for. /// The specifying which extras to return. All other overloads default to returning all extras. /// The number of photos per page. /// The page to return. /// A object containing the list of photos. public Photos GroupPoolGetPhotos(string groupId, string tags, string userId, PhotoSearchExtras extras, int perPage, int page) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.groups.pools.getPhotos"); parameters.Add("group_id", groupId); if( tags != null && tags.Length > 0 )parameters.Add("tags", tags); if( perPage > 0 ) parameters.Add("per_page", perPage.ToString()); if( page > 0 ) parameters.Add("page", page.ToString()); if( userId != null && userId.Length > 0 ) parameters.Add("user_id", userId); if( extras != PhotoSearchExtras.None ) parameters.Add("extras", Utils.ExtrasToString(extras)); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } #endregion #region [ Interestingness ] /// /// Gets a list of photos from the most recent interstingness list. /// /// Number of photos per page. /// The page number to return. /// enumeration. /// instance containing list of photos. public Photos InterestingnessGetList(PhotoSearchExtras extras, int perPage, int page) { return InterestingnessGetList(DateTime.MinValue, extras, perPage, page); } /// /// Gets a list of photos from the interstingness list for the specified date. /// /// The date to return the interestingness list for. /// instance containing list of photos. public Photos InterestingnessGetList(DateTime date) { return InterestingnessGetList(date, PhotoSearchExtras.All, 0, 0); } /// /// Gets a list of photos from the most recent interstingness list. /// /// instance containing list of photos. public Photos InterestingnessGetList() { return InterestingnessGetList(DateTime.MinValue, PhotoSearchExtras.All, 0, 0); } /// /// Gets a list of photos from the most recent interstingness list. /// /// The date to return the interestingness photos for. /// The extra parameters to return along with the search results. /// See for more details. /// The number of results to return per page. /// The page of the results to return. /// public Photos InterestingnessGetList(DateTime date, PhotoSearchExtras extras, int perPage, int page) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.interestingness.getList"); if( date > DateTime.MinValue ) parameters.Add("date", date.ToString("yyyy-MM-dd")); if( perPage > 0 ) parameters.Add("per_page", perPage.ToString()); if( page > 0 ) parameters.Add("page", page.ToString()); if( extras != PhotoSearchExtras.None ) parameters.Add("extras", Utils.ExtrasToString(extras)); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } #endregion #region [ Notes ] /// /// Add a note to a picture. /// /// The photo id to add the note to. /// The X co-ordinate of the upper left corner of the note. /// The Y co-ordinate of the upper left corner of the note. /// The width of the note. /// The height of the note. /// The text in the note. /// public string NotesAdd(string photoId, int noteX, int noteY, int noteWidth, int noteHeight, string noteText) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.notes.add"); parameters.Add("photo_id", photoId); parameters.Add("note_x", noteX.ToString()); parameters.Add("note_y", noteY.ToString()); parameters.Add("note_w", noteWidth.ToString()); parameters.Add("note_h", noteHeight.ToString()); parameters.Add("note_text", noteText); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { foreach(XmlElement element in response.AllElements) { return element.Attributes["id", ""].Value; } return string.Empty; } else { throw new FlickrException(response.Error); } } /// /// Edit and update a note. /// /// The ID of the note to update. /// The X co-ordinate of the upper left corner of the note. /// The Y co-ordinate of the upper left corner of the note. /// The width of the note. /// The height of the note. /// The new text in the note. public void NotesEdit(string noteId, int noteX, int noteY, int noteWidth, int noteHeight, string noteText) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.notes.edit"); parameters.Add("note_id", noteId); parameters.Add("note_x", noteX.ToString()); parameters.Add("note_y", noteY.ToString()); parameters.Add("note_w", noteWidth.ToString()); parameters.Add("note_h", noteHeight.ToString()); parameters.Add("note_text", noteText); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } /// /// Delete an existing note. /// /// The ID of the note. public void NotesDelete(string noteId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.notes.delete"); parameters.Add("note_id", noteId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } #endregion #region [ People ] /// /// Used to fid a flickr users details by specifying their email address. /// /// The email address to search on. /// The object containing the matching details. /// A FlickrException is raised if the email address is not found. public FoundUser PeopleFindByEmail(string emailAddress) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.people.findByEmail"); parameters.Add("api_key", _apiKey); parameters.Add("find_email", emailAddress); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return new FoundUser(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } /// /// Returns a object matching the screen name. /// /// The screen name or username of the user. /// A class containing the userId and username of the user. /// A FlickrException is raised if the email address is not found. public FoundUser PeopleFindByUsername(string username) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.people.findByUsername"); parameters.Add("api_key", _apiKey); parameters.Add("username", username); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return new FoundUser(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } /// /// Gets the object for the given user id. /// /// The user id to find. /// The object containing the users details. public Person PeopleGetInfo(string userId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.people.getInfo"); parameters.Add("api_key", _apiKey); parameters.Add("user_id", userId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Person; } else { throw new FlickrException(response.Error); } } /// /// Gets the upload status of the authenticated user. /// /// The object containing the users details. public UserStatus PeopleGetUploadStatus() { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.people.getUploadStatus"); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return new UserStatus(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } /// /// Get a list of public groups for a user. /// /// The user id to get groups for. /// An array of instances. public PublicGroupInfo[] PeopleGetPublicGroups(string userId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.people.getPublicGroups"); parameters.Add("api_key", _apiKey); parameters.Add("user_id", userId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return PublicGroupInfo.GetPublicGroupInfo(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } /// /// Gets a users public photos. Excludes private photos. /// /// The user id of the user. /// The collection of photos contained within a object. public Photos PeopleGetPublicPhotos(string userId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.people.getPublicPhotos"); parameters.Add("api_key", _apiKey); parameters.Add("user_id", userId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } #endregion #region [ Photos ] /// /// Add a selection of tags to a photo. /// /// The photo id of the photo. /// An array of strings containing the tags. /// True if the tags are added successfully. public void PhotosAddTags(string photoId, string[] tags) { string s = string.Join(",", tags); PhotosAddTags(photoId, s); } /// /// Add a selection of tags to a photo. /// /// The photo id of the photo. /// An string of comma delimited tags. /// True if the tags are added successfully. public void PhotosAddTags(string photoId, string tags) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.addTags"); parameters.Add("photo_id", photoId); parameters.Add("tags", tags); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } /// /// Delete a photo from Flickr. /// /// /// Requires Delete permissions. Also note, photos cannot be recovered once deleted. /// The ID of the photo to delete. public void PhotosDelete(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.delete"); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } /// /// Get all the contexts (group, set and photostream 'next' and 'previous' /// pictures) for a photo. /// /// The photo id of the photo to get the contexts for. /// An instance of the class. public AllContexts PhotosGetAllContexts(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getAllContexts"); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { AllContexts contexts = new AllContexts(response.AllElements); return contexts; } else { throw new FlickrException(response.Error); } } /// /// Gets the most recent 10 photos from your contacts. /// /// An instance of the class containing the photos. public Photos PhotosGetContactsPhotos() { return PhotosGetContactsPhotos(0, false, false, false); } /// /// Gets the most recent photos from your contacts. /// /// Returns the most recent photos from all your contact, excluding yourself. /// The number of photos to return, from between 10 and 50. /// An instance of the class containing the photos. /// /// Throws a exception if the cound /// is not between 10 and 50, or 0. public Photos PhotosGetContactsPhotos(long count) { return PhotosGetContactsPhotos(count, false, false, false); } /// /// Gets your contacts most recent photos. /// /// The number of photos to return, from between 10 and 50. /// If true only returns photos from contacts marked as /// 'friends'. /// If true only returns a single photo for each of your contacts. /// Ignores the count if this is true. /// If true includes yourself in the group of people to /// return photos for. /// An instance of the class containing the photos. /// /// Throws a exception if the cound /// is not between 10 and 50, or 0. public Photos PhotosGetContactsPhotos(long count, bool justFriends, bool singlePhoto, bool includeSelf) { if( count != 0 && (count < 10 || count > 50) && !singlePhoto ) { throw new ArgumentOutOfRangeException("count", count, "Count must be between 10 and 50."); } Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getContactsPhotos"); if( count > 0 && !singlePhoto ) parameters.Add("count", count.ToString()); if( justFriends ) parameters.Add("just_friends", "1"); if( singlePhoto ) parameters.Add("single_photo", "1"); if( includeSelf ) parameters.Add("include_self", "1"); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } /// /// Gets the public photos for given users ID's contacts. /// /// The user ID whose contacts you wish to get photos for. /// A object containing details of the photos returned. public Photos PhotosGetContactsPublicPhotos(string userId) { return PhotosGetContactsPublicPhotos(userId, 0, false, false, false, PhotoSearchExtras.All); } /// /// Gets the public photos for given users ID's contacts. /// /// The user ID whose contacts you wish to get photos for. /// A list of extra details to return for each photo. /// A object containing details of the photos returned. public Photos PhotosGetContactsPublicPhotos(string userId, PhotoSearchExtras extras) { return PhotosGetContactsPublicPhotos(userId, 0, false, false, false, extras); } /// /// Gets the public photos for given users ID's contacts. /// /// The user ID whose contacts you wish to get photos for. /// The number of photos to return. Defaults to 10, maximum is 50. /// A object containing details of the photos returned. public Photos PhotosGetContactsPublicPhotos(string userId, long count) { return PhotosGetContactsPublicPhotos(userId, count, false, false, false, PhotoSearchExtras.All); } /// /// Gets the public photos for given users ID's contacts. /// /// The user ID whose contacts you wish to get photos for. /// The number of photos to return. Defaults to 10, maximum is 50. /// A list of extra details to return for each photo. /// A object containing details of the photos returned. public Photos PhotosGetContactsPublicPhotos(string userId, long count, PhotoSearchExtras extras) { return PhotosGetContactsPublicPhotos(userId, count, false, false, false, extras); } /// /// Gets the public photos for given users ID's contacts. /// /// The user ID whose contacts you wish to get photos for. /// The number of photos to return. Defaults to 10, maximum is 50. /// True to just return photos from friends and family (excluding regular contacts). /// True to return just a single photo for each contact. /// True to include photos from the user ID specified as well. /// public Photos PhotosGetContactsPublicPhotos(string userId, long count, bool justFriends, bool singlePhoto, bool includeSelf) { return PhotosGetContactsPublicPhotos(userId, count, justFriends, singlePhoto, includeSelf, PhotoSearchExtras.All); } /// /// Gets the public photos for given users ID's contacts. /// /// The user ID whose contacts you wish to get photos for. /// The number of photos to return. Defaults to 10, maximum is 50. /// True to just return photos from friends and family (excluding regular contacts). /// True to return just a single photo for each contact. /// True to include photos from the user ID specified as well. /// A list of extra details to return for each photo. /// public Photos PhotosGetContactsPublicPhotos(string userId, long count, bool justFriends, bool singlePhoto, bool includeSelf, PhotoSearchExtras extras) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getContactsPublicPhotos"); parameters.Add("api_key", _apiKey); parameters.Add("user_id", userId); if( count > 0 ) parameters.Add("count", count.ToString()); if( justFriends ) parameters.Add("just_friends", "1"); if( singlePhoto ) parameters.Add("single_photo", "1"); if( includeSelf ) parameters.Add("include_self", "1"); if( extras != PhotoSearchExtras.None ) parameters.Add("extras", Utils.ExtrasToString(extras)); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } /// /// Gets the context of the photo in the users photostream. /// /// The ID of the photo to return the context for. /// public Context PhotosGetContext(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getContext"); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { Context c = new Context(); c.Count = response.ContextCount.Count; c.NextPhoto = response.ContextNextPhoto; c.PreviousPhoto = response.ContextPrevPhoto; return c; } else { throw new FlickrException(response.Error); } } /// /// Returns count of photos between each pair of dates in the list. /// /// If you pass in DateA, DateB and DateC it returns /// a list of the number of photos between DateA and DateB, /// followed by the number between DateB and DateC. /// More parameters means more sets. /// Array of objects. /// class instance. public PhotoCounts PhotosGetCounts(DateTime[] dates) { return PhotosGetCounts(dates, false); } /// /// Returns count of photos between each pair of dates in the list. /// /// If you pass in DateA, DateB and DateC it returns /// a list of the number of photos between DateA and DateB, /// followed by the number between DateB and DateC. /// More parameters means more sets. /// Array of objects. /// Boolean parameter to specify if the dates are the taken date, or uploaded date. /// class instance. public PhotoCounts PhotosGetCounts(DateTime[] dates, bool taken) { StringBuilder s = new StringBuilder(dates.Length * 20); foreach(DateTime d in dates) { s.Append(Utils.DateToUnixTimestamp(d)); s.Append(","); } if( s.Length > 0 ) s.Remove(s.Length-2,1); if( taken ) return PhotosGetCounts(null, s.ToString()); else return PhotosGetCounts(s.ToString(), null); } /// /// Returns count of photos between each pair of dates in the list. /// /// If you pass in DateA, DateB and DateC it returns /// a list of the number of photos between DateA and DateB, /// followed by the number between DateB and DateC. /// More parameters means more sets. /// Comma-delimited list of dates in unix timestamp format. Optional. /// class instance. public PhotoCounts PhotosGetCounts(string dates) { return PhotosGetCounts(dates, null); } /// /// Returns count of photos between each pair of dates in the list. /// /// If you pass in DateA, DateB and DateC it returns /// a list of the number of photos between DateA and DateB, /// followed by the number between DateB and DateC. /// More parameters means more sets. /// Comma-delimited list of dates in unix timestamp format. Optional. /// Comma-delimited list of dates in unix timestamp format. Optional. /// class instance. public PhotoCounts PhotosGetCounts(string dates, string taken_dates) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getContactsPhotos"); if( dates != null && dates.Length > 0 ) parameters.Add("dates", dates); if( taken_dates != null && taken_dates.Length > 0 ) parameters.Add("taken_dates", taken_dates); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.PhotoCounts; } else { throw new FlickrException(response.Error); } } /// /// Gets the EXIF data for a given Photo ID. /// /// The Photo ID of the photo to return the EXIF data for. /// An instance of the class containing the EXIF data. public ExifPhoto PhotosGetExif(string photoId) { return PhotosGetExif(photoId, null); } /// /// Gets the EXIF data for a given Photo ID. /// /// The Photo ID of the photo to return the EXIF data for. /// The secret of the photo. If the secret is specified then /// authentication checks are bypassed. /// An instance of the class containing the EXIF data. public ExifPhoto PhotosGetExif(string photoId, string secret) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getExif"); parameters.Add("photo_id", photoId); if( secret != null ) parameters.Add("secret", secret); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { ExifPhoto e = new ExifPhoto(response.PhotoInfo.PhotoId, response.PhotoInfo.Secret, response.PhotoInfo.Server, response.PhotoInfo.ExifTagCollection); return e; } else { throw new FlickrException(response.Error); } } /// /// Get information about a photo. The calling user must have permission to view the photo. /// /// The id of the photo to fetch information for. /// A class detailing the properties of the photo. public PhotoInfo PhotosGetInfo(string photoId) { return PhotosGetInfo(photoId, null); } /// /// Get information about a photo. The calling user must have permission to view the photo. /// /// The id of the photo to fetch information for. /// The secret for the photo. If the correct secret is passed then permissions checking is skipped. This enables the 'sharing' of individual photos by passing around the id and secret. /// A class detailing the properties of the photo. public PhotoInfo PhotosGetInfo(string photoId, string secret) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getInfo"); parameters.Add("photo_id", photoId); if( secret != null ) parameters.Add("secret", secret); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.PhotoInfo; } else { throw new FlickrException(response.Error); } } /// /// Get permissions for a photo. /// /// The id of the photo to get permissions for. /// An instance of the class containing the permissions of the specified photo. public PhotoPermissions PhotosGetPerms(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getPerms"); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return new PhotoPermissions(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } /// /// Returns a list of the latest public photos uploaded to flickr. /// /// A class containing the list of photos. public Photos PhotosGetRecent() { return PhotosGetRecent(0, 0, PhotoSearchExtras.All); } /// /// Returns a list of the latest public photos uploaded to flickr. /// /// A comma-delimited list of extra information to fetch for each returned record. /// A class containing the list of photos. public Photos PhotosGetRecent(PhotoSearchExtras extras) { return PhotosGetRecent(0, 0, extras); } /// /// Returns a list of the latest public photos uploaded to flickr. /// /// The page of results to return. If this argument is omitted, it defaults to 1. /// Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500. /// A class containing the list of photos. public Photos PhotosGetRecent(long perPage, long page) { return PhotosGetRecent(perPage, page, PhotoSearchExtras.All); } /// /// Returns a list of the latest public photos uploaded to flickr. /// /// A comma-delimited list of extra information to fetch for each returned record. /// The page of results to return. If this argument is omitted, it defaults to 1. /// Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500. /// A class containing the list of photos. public Photos PhotosGetRecent(long perPage, long page, PhotoSearchExtras extras) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getRecent"); parameters.Add("api_key", _apiKey); if( perPage > 0 ) parameters.Add("per_page", perPage.ToString()); if( page > 0 ) parameters.Add("page", page.ToString()); if( extras != PhotoSearchExtras.None ) parameters.Add("extras", Utils.ExtrasToString(extras)); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } /// /// Return a list of your photos that have been recently created or which have been recently modified. /// Recently modified may mean that the photo's metadata (title, description, tags) /// may have been changed or a comment has been added (or just modified somehow :-) /// /// The date from which modifications should be compared. /// A list of extra information to fetch for each returned record. /// Returns a instance containing the list of photos. public Photos PhotosRecentlyUpdated(DateTime minDate, PhotoSearchExtras extras) { return PhotosRecentlyUpdated(minDate, extras, 0, 0); } /// /// Return a list of your photos that have been recently created or which have been recently modified. /// Recently modified may mean that the photo's metadata (title, description, tags) /// may have been changed or a comment has been added (or just modified somehow :-) /// /// The date from which modifications should be compared. /// Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500. /// The page of results to return. If this argument is omitted, it defaults to 1. /// Returns a instance containing the list of photos. public Photos PhotosRecentlyUpdated(DateTime minDate, int perPage, int page) { return PhotosRecentlyUpdated(minDate, PhotoSearchExtras.None, perPage, page); } /// /// Return a list of your photos that have been recently created or which have been recently modified. /// Recently modified may mean that the photo's metadata (title, description, tags) /// may have been changed or a comment has been added (or just modified somehow :-) /// /// The date from which modifications should be compared. /// Returns a instance containing the list of photos. public Photos PhotosRecentlyUpdated(DateTime minDate) { return PhotosRecentlyUpdated(minDate, PhotoSearchExtras.None, 0, 0); } /// /// Return a list of your photos that have been recently created or which have been recently modified. /// Recently modified may mean that the photo's metadata (title, description, tags) /// may have been changed or a comment has been added (or just modified somehow :-) /// /// The date from which modifications should be compared. /// A list of extra information to fetch for each returned record. /// Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500. /// The page of results to return. If this argument is omitted, it defaults to 1. /// Returns a instance containing the list of photos. public Photos PhotosRecentlyUpdated(DateTime minDate, PhotoSearchExtras extras, int perPage, int page) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.recentlyUpdated"); parameters.Add("min_date", Utils.DateToUnixTimestamp(minDate).ToString()); if( extras != PhotoSearchExtras.None ) parameters.Add("extras", Utils.ExtrasToString(extras)); if( perPage > 0 ) parameters.Add("per_page", perPage.ToString()); if( page > 0 ) parameters.Add("page", page.ToString()); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } /// /// Returns the available sizes for a photo. The calling user must have permission to view the photo. /// /// The id of the photo to fetch size information for. /// A class whose property is an array of objects. public Sizes PhotosGetSizes(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getSizes"); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Sizes; } else { throw new FlickrException(response.Error); } } /// /// Returns a list of your photos with no tags. /// /// A class containing the list of photos. public Photos PhotosGetUntagged() { return PhotosGetUntagged(0, 0, PhotoSearchExtras.All); } /// /// Returns a list of your photos with no tags. /// /// A comma-delimited list of extra information to fetch for each returned record. /// A class containing the list of photos. public Photos PhotosGetUntagged(PhotoSearchExtras extras) { return PhotosGetUntagged(0, 0, extras); } /// /// Returns a list of your photos with no tags. /// /// The page of results to return. If this argument is omitted, it defaults to 1. /// Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500. /// A class containing the list of photos. public Photos PhotosGetUntagged(int perPage, int page) { return PhotosGetUntagged(perPage, page, PhotoSearchExtras.All); } /// /// Returns a list of your photos with no tags. /// /// A comma-delimited list of extra information to fetch for each returned record. /// The page of results to return. If this argument is omitted, it defaults to 1. /// Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500. /// A class containing the list of photos. public Photos PhotosGetUntagged(int perPage, int page, PhotoSearchExtras extras) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getUntagged"); if( perPage > 0 ) parameters.Add("per_page", perPage.ToString()); if( page > 0 ) parameters.Add("page", page.ToString()); if( extras != PhotoSearchExtras.None ) parameters.Add("extras", Utils.ExtrasToString(extras)); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } /// /// Gets a list of photos not in sets. Defaults to include all extra fields. /// /// instance containing list of photos. public Photos PhotosGetNotInSet() { return PhotosGetNotInSet(new PartialSearchOptions()); } /// /// Gets a specific page of the list of photos which are not in sets. /// Defaults to include all extra fields. /// /// The page number to return. /// instance containing list of photos. public Photos PhotosGetNotInSet(int page) { return PhotosGetNotInSet(0, page, PhotoSearchExtras.None); } /// /// Gets a specific page of the list of photos which are not in sets. /// Defaults to include all extra fields. /// /// Number of photos per page. /// The page number to return. /// instance containing list of photos. public Photos PhotosGetNotInSet(int perPage, int page) { return PhotosGetNotInSet(perPage, page, PhotoSearchExtras.None); } /// /// Gets a list of a users photos which are not in a set. /// /// Number of photos per page. /// The page number to return. /// enumeration. /// instance containing list of photos. public Photos PhotosGetNotInSet(int perPage, int page, PhotoSearchExtras extras) { PartialSearchOptions options = new PartialSearchOptions(); options.PerPage = perPage; options.Page = page; options.Extras = extras; return PhotosGetNotInSet(options); } /// /// Gets a list of the authenticated users photos which are not in a set. /// /// A selection of options to filter/sort by. /// A collection of photos in the class. public Photos PhotosGetNotInSet(PartialSearchOptions options) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getNotInSet"); Utils.PartialOptionsIntoArray(options, parameters); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } /// /// Gets a list of all current licenses. /// /// instance. public Licenses PhotosLicensesGetInfo() { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.licenses.getInfo"); parameters.Add("api_key", _apiKey); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Licenses; } else { throw new FlickrException(response.Error); } } /// /// Remove an existing tag. /// /// The id of the tag, as returned by or similar method. /// True if the tag was removed. public bool PhotosRemoveTag(string tagId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.removeTag"); parameters.Add("tag_id", tagId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } /// /// Search for photos containing text, rather than tags. /// /// The user whose photos you wish to search for. /// The text you want to search for in titles and descriptions. /// A instance. public Photos PhotosSearchText(string userId, string text) { return PhotosSearch(userId, "", 0, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos containing text, rather than tags. /// /// The user whose photos you wish to search for. /// The text you want to search for in titles and descriptions. /// Optional extras to return. /// A instance. public Photos PhotosSearchText(string userId, string text, PhotoSearchExtras extras) { return PhotosSearch(userId, "", 0, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, extras); } /// /// Search for photos containing text, rather than tags. /// /// The user whose photos you wish to search for. /// The text you want to search for in titles and descriptions. /// The license type to return. /// A instance. public Photos PhotosSearchText(string userId, string text, int license) { return PhotosSearch(userId, "", 0, text, DateTime.MinValue, DateTime.MinValue, license, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos containing text, rather than tags. /// /// The user whose photos you wish to search for. /// The text you want to search for in titles and descriptions. /// The license type to return. /// Optional extras to return. /// A instance. public Photos PhotosSearchText(string userId, string text, int license, PhotoSearchExtras extras) { return PhotosSearch(userId, "", 0, text, DateTime.MinValue, DateTime.MinValue, license, 0, 0, extras); } /// /// Search for photos containing text, rather than tags. /// /// The text you want to search for in titles and descriptions. /// Optional extras to return. /// A instance. public Photos PhotosSearchText(string text, PhotoSearchExtras extras) { return PhotosSearch(null, "", 0, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, extras); } /// /// Search for photos containing text, rather than tags. /// /// The text you want to search for in titles and descriptions. /// A instance. public Photos PhotosSearchText(string text) { return PhotosSearch(null, "", 0, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos containing text, rather than tags. /// /// The text you want to search for in titles and descriptions. /// The license type to return. /// A instance. public Photos PhotosSearchText(string text, int license) { return PhotosSearch(null, "", 0, text, DateTime.MinValue, DateTime.MinValue, license, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos containing text, rather than tags. /// /// The text you want to search for in titles and descriptions. /// The license type to return. /// Optional extras to return. /// A instance. public Photos PhotosSearchText(string text, int license, PhotoSearchExtras extras) { return PhotosSearch(null, "", 0, text, DateTime.MinValue, DateTime.MinValue, license, 0, 0, extras); } /// /// Search for photos containing an array of tags. /// /// An array of tags to search for. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string[] tags, PhotoSearchExtras extras) { return PhotosSearch(null, tags, 0, "", DateTime.MinValue, DateTime.MinValue, 0, 0, 0, extras); } /// /// Search for photos containing an array of tags. /// /// An array of tags to search for. /// A instance. public Photos PhotosSearch(string[] tags) { return PhotosSearch(null, tags, 0, "", DateTime.MinValue, DateTime.MinValue, 0, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos containing an array of tags. /// /// An array of tags to search for. /// The license type to return. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string[] tags, int license, PhotoSearchExtras extras) { return PhotosSearch(null, tags, 0, "", DateTime.MinValue, DateTime.MinValue, license, 0, 0, extras); } /// /// Search for photos containing an array of tags. /// /// An array of tags to search for. /// The license type to return. /// A instance. public Photos PhotosSearch(string[] tags, int license) { return PhotosSearch(null, tags, 0, "", DateTime.MinValue, DateTime.MinValue, license, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos. /// /// An array of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Number of photos to return per page. /// The page number to return. /// A instance. public Photos PhotosSearch(string[] tags, TagMode tagMode, string text, int perPage, int page) { return PhotosSearch(null, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, perPage, page, PhotoSearchExtras.All); } /// /// Search for photos. /// /// An array of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Number of photos to return per page. /// The page number to return. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string[] tags, TagMode tagMode, string text, int perPage, int page, PhotoSearchExtras extras) { return PhotosSearch(null, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, perPage, page, extras); } /// /// Search for photos. /// /// An array of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// A instance. public Photos PhotosSearch(string[] tags, TagMode tagMode, string text) { return PhotosSearch(null, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos. /// /// An array of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string[] tags, TagMode tagMode, string text, PhotoSearchExtras extras) { return PhotosSearch(null, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, extras); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// An array of tags to search for. /// A instance. public Photos PhotosSearch(string userId, string[] tags) { return PhotosSearch(userId, tags, 0, "", DateTime.MinValue, DateTime.MinValue, 0, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// An array of tags to search for. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string userId, string[] tags, PhotoSearchExtras extras) { return PhotosSearch(userId, tags, 0, "", DateTime.MinValue, DateTime.MinValue, 0, 0, 0, extras); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// An array of tags to search for. /// The license type to return. /// A instance. public Photos PhotosSearch(string userId, string[] tags, int license) { return PhotosSearch(userId, tags, 0, "", DateTime.MinValue, DateTime.MinValue, license, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// An array of tags to search for. /// The license type to return. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string userId, string[] tags, int license, PhotoSearchExtras extras) { return PhotosSearch(userId, tags, 0, "", DateTime.MinValue, DateTime.MinValue, license, 0, 0, extras); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// An array of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Number of photos to return per page. /// The page number to return. /// A instance. public Photos PhotosSearch(string userId, string[] tags, TagMode tagMode, string text, int perPage, int page) { return PhotosSearch(userId, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, perPage, page, PhotoSearchExtras.All); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// An array of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Number of photos to return per page. /// The page number to return. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string userId, string[] tags, TagMode tagMode, string text, int perPage, int page, PhotoSearchExtras extras) { return PhotosSearch(userId, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, perPage, page, extras); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// An array of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// A instance. public Photos PhotosSearch(string userId, string[] tags, TagMode tagMode, string text) { return PhotosSearch(userId, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// An array of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string userId, string[] tags, TagMode tagMode, string text, PhotoSearchExtras extras) { return PhotosSearch(userId, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, extras); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// An array of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// The minimum upload date. /// The maxmimum upload date. /// The license type to return. /// Number of photos to return per page. /// The page number to return. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string userId, string[] tags, TagMode tagMode, string text, DateTime minUploadDate, DateTime maxUploadDate, int license, int perPage, int page, PhotoSearchExtras extras) { return PhotosSearch(userId, String.Join(",", tags), tagMode, text, minUploadDate, maxUploadDate, license, perPage, page, extras); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// An array of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// The minimum upload date. /// The maxmimum upload date. /// The license type to return. /// Number of photos to return per page. /// The page number to return. /// A instance. public Photos PhotosSearch(string userId, string[] tags, TagMode tagMode, string text, DateTime minUploadDate, DateTime maxUploadDate, int license, int perPage, int page) { return PhotosSearch(userId, String.Join(",", tags), tagMode, text, minUploadDate, maxUploadDate, license, perPage, page, PhotoSearchExtras.All); } // PhotoSearch - tags versions /// /// Search for photos. /// /// A comma seperated list of tags to search for. /// The license type to return. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string tags, int license, PhotoSearchExtras extras) { return PhotosSearch(null, tags, 0, "", DateTime.MinValue, DateTime.MinValue, license, 0, 0, extras); } /// /// Search for photos. /// /// A comma seperated list of tags to search for. /// The license type to return. /// A instance. public Photos PhotosSearch(string tags, int license) { return PhotosSearch(null, tags, 0, "", DateTime.MinValue, DateTime.MinValue, license, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos. /// /// A comma seperated list of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Number of photos to return per page. /// The page number to return. /// A instance. public Photos PhotosSearch(string tags, TagMode tagMode, string text, int perPage, int page) { return PhotosSearch(null, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, perPage, page, PhotoSearchExtras.All); } /// /// Search for photos. /// /// A comma seperated list of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Number of photos to return per page. /// The page number to return. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string tags, TagMode tagMode, string text, int perPage, int page, PhotoSearchExtras extras) { return PhotosSearch(null, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, perPage, page, extras); } /// /// Search for photos. /// /// A comma seperated list of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// A instance. public Photos PhotosSearch(string tags, TagMode tagMode, string text) { return PhotosSearch(null, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos. /// /// A comma seperated list of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string tags, TagMode tagMode, string text, PhotoSearchExtras extras) { return PhotosSearch(null, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, extras); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// A comma seperated list of tags to search for. /// A instance. public Photos PhotosSearch(string userId, string tags) { return PhotosSearch(userId, tags, 0, "", DateTime.MinValue, DateTime.MinValue, 0, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// A comma seperated list of tags to search for. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string userId, string tags, PhotoSearchExtras extras) { return PhotosSearch(userId, tags, 0, "", DateTime.MinValue, DateTime.MinValue, 0, 0, 0, extras); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// A comma seperated list of tags to search for. /// The license type to return. /// A instance. public Photos PhotosSearch(string userId, string tags, int license) { return PhotosSearch(userId, tags, 0, "", DateTime.MinValue, DateTime.MinValue, license, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// A comma seperated list of tags to search for. /// The license type to return. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string userId, string tags, int license, PhotoSearchExtras extras) { return PhotosSearch(userId, tags, 0, "", DateTime.MinValue, DateTime.MinValue, license, 0, 0, extras); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// A comma seperated list of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Number of photos to return per page. /// The page number to return. /// A instance. public Photos PhotosSearch(string userId, string tags, TagMode tagMode, string text, int perPage, int page) { return PhotosSearch(userId, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, perPage, page, PhotoSearchExtras.All); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// A comma seperated list of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Number of photos to return per page. /// The page number to return. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string userId, string tags, TagMode tagMode, string text, int perPage, int page, PhotoSearchExtras extras) { return PhotosSearch(userId, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, perPage, page, extras); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// A comma seperated list of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// A instance. public Photos PhotosSearch(string userId, string tags, TagMode tagMode, string text) { return PhotosSearch(userId, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, PhotoSearchExtras.All); } /// /// Search for photos. /// /// The ID of the user to search the photos of. /// A comma seperated list of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Optional extras to return. /// A instance. public Photos PhotosSearch(string userId, string tags, TagMode tagMode, string text, PhotoSearchExtras extras) { return PhotosSearch(userId, tags, tagMode, text, DateTime.MinValue, DateTime.MinValue, 0, 0, 0, extras); } // Actual PhotoSearch function /// /// Search for photos. /// /// The ID of the user to search the photos of. /// A comma seperated list of tags to search for. /// Match all tags, or any tag. /// Text to search for in photo title or description. /// Number of photos to return per page. /// The page number to return. /// Optional extras to return. /// The minimum upload date. /// The maxmimum upload date. /// The license type to return. /// A instance. public Photos PhotosSearch(string userId, string tags, TagMode tagMode, string text, DateTime minUploadDate, DateTime maxUploadDate, int license, int perPage, int page, PhotoSearchExtras extras) { PhotoSearchOptions options = new PhotoSearchOptions(); options.UserId = userId; options.Tags = tags; options.TagMode = tagMode; options.Text = text; options.MinUploadDate = minUploadDate; options.MaxUploadDate = maxUploadDate; options.AddLicense(license); options.PerPage = perPage; options.Page = page; options.Extras = extras; return PhotosSearch(options); } /// /// Search for a set of photos, based on the value of the parameters. /// /// The parameters to search for. /// A collection of photos contained within a object. public Photos PhotosSearch(PhotoSearchOptions options) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.search"); if( options.UserId != null && options.UserId.Length > 0 ) parameters.Add("user_id", options.UserId); if( options.Text != null && options.Text.Length > 0 ) parameters.Add("text", options.Text); if( options.Tags != null && options.Tags.Length > 0 ) parameters.Add("tags", options.Tags); if( options.TagMode != TagMode.None ) parameters.Add("tag_mode", options.TagModeString); if( options.MinUploadDate != DateTime.MinValue ) parameters.Add("min_upload_date", Utils.DateToUnixTimestamp(options.MinUploadDate).ToString()); if( options.MaxUploadDate != DateTime.MinValue ) parameters.Add("max_upload_date", Utils.DateToUnixTimestamp(options.MaxUploadDate).ToString()); if( options.MinTakenDate != DateTime.MinValue ) parameters.Add("min_taken_date", options.MinTakenDate.ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)); if( options.MaxTakenDate != DateTime.MinValue ) parameters.Add("max_taken_date", options.MaxTakenDate.ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)); if( options.Licenses.Length != 0 ) { string lic = ""; for(int i = 0; i < options.Licenses.Length; i++) { if( i > 0 ) lic += ","; lic += Convert.ToString(options.Licenses[i]); } parameters.Add("license", lic); } if( options.PerPage != 0 ) parameters.Add("per_page", options.PerPage.ToString()); if( options.Page != 0 ) parameters.Add("page", options.Page.ToString()); if( options.Extras != PhotoSearchExtras.None ) parameters.Add("extras", options.ExtrasString); if( options.SortOrder != PhotoSearchSortOrder.None ) parameters.Add("sort", options.SortOrderString); if( options.PrivacyFilter != PrivacyFilter.None ) parameters.Add("privacy_filter", options.PrivacyFilter.ToString("d")); if( options.BoundaryBox.IsSet ) parameters.Add("bbox", options.BoundaryBox.ToString()); if( options.Accuracy != GeoAccuracy.None ) parameters.Add("accuracy", options.Accuracy.ToString("d")); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } /// /// Set the date taken for a photo. /// /// /// All dates are assumed to be GMT. It is the developers responsibility to change dates to the local users /// timezone. /// /// The id of the photo to set the date taken for. /// The date taken. /// The granularity of the date taken. /// True if the date was updated successfully. public bool PhotosSetDates(string photoId, DateTime dateTaken, DateGranularity granularity) { return PhotosSetDates(photoId, DateTime.MinValue, dateTaken, granularity); } /// /// Set the date the photo was posted (uploaded). This will affect the order in which photos /// are seen in your photostream. /// /// /// All dates are assumed to be GMT. It is the developers responsibility to change dates to the local users /// timezone. /// /// The id of the photo to set the date posted. /// The new date to set the date posted too. /// True if the date was updated successfully. public bool PhotosSetDates(string photoId, DateTime datePosted) { return PhotosSetDates(photoId, datePosted, DateTime.MinValue, DateGranularity.FullDate); } /// /// Set the date the photo was posted (uploaded) and the date the photo was taken. /// Changing the date posted will affect the order in which photos are seen in your photostream. /// /// /// All dates are assumed to be GMT. It is the developers responsibility to change dates to the local users /// timezone. /// /// The id of the photo to set the dates. /// The new date to set the date posted too. /// The new date to set the date taken too. /// The granularity of the date taken. /// True if the dates where updated successfully. public bool PhotosSetDates(string photoId, DateTime datePosted, DateTime dateTaken, DateGranularity granularity) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.setDates"); parameters.Add("photo_id", photoId); if( datePosted != DateTime.MinValue ) parameters.Add("date_posted", Utils.DateToUnixTimestamp(datePosted).ToString()); if( dateTaken != DateTime.MinValue ) { parameters.Add("date_taken", dateTaken.ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)); parameters.Add("date_taken_granularity", granularity.ToString("d")); } FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } /// /// Sets the title and description of the photograph. /// /// The numerical photoId of the photograph. /// The new title of the photograph. /// The new description of the photograph. /// True when the operation is successful. /// Thrown when the photo id cannot be found. public bool PhotosSetMeta(string photoId, string title, string description) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.setMeta"); parameters.Add("photo_id", photoId); parameters.Add("title", title); parameters.Add("description", description); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } /// /// Set the permissions on a photo. /// /// The id of the photo to update. /// 1 if the photo is public, 0 if it is not. /// 1 if the photo is viewable by friends, 0 if it is not. /// 1 if the photo is viewable by family, 0 if it is not. /// Who can add comments. See for more details. /// Who can add metadata (notes and tags). See for more details. public void PhotosSetPerms(string photoId, int isPublic, int isFriend, int isFamily, PermissionComment permComment, PermissionAddMeta permAddMeta) { PhotosSetPerms(photoId, (isPublic==1), (isFriend==1), (isFamily==1), permComment, permAddMeta); } /// /// Set the permissions on a photo. /// /// The id of the photo to update. /// True if the photo is public, False if it is not. /// True if the photo is viewable by friends, False if it is not. /// True if the photo is viewable by family, False if it is not. /// Who can add comments. See for more details. /// Who can add metadata (notes and tags). See for more details. public void PhotosSetPerms(string photoId, bool isPublic, bool isFriend, bool isFamily, PermissionComment permComment, PermissionAddMeta permAddMeta) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.setPerms"); parameters.Add("photo_id", photoId); parameters.Add("is_public", (isPublic?"1":"0")); parameters.Add("is_friend", (isFriend?"1":"0")); parameters.Add("is_family", (isFamily?"1":"0")); parameters.Add("perm_comment", permComment.ToString("d")); parameters.Add("perm_addmeta", permAddMeta.ToString("d")); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } /// /// Set the tags for a photo. /// /// /// This will remove all old tags and add these new ones specified. See /// to just add new tags without deleting old ones. /// /// The id of the photo to update. /// An array of tags. /// True if the photo was updated successfully. public bool PhotosSetTags(string photoId, string[] tags) { string s = string.Join(",", tags); return PhotosSetTags(photoId, s); } /// /// Set the tags for a photo. /// /// /// This will remove all old tags and add these new ones specified. See /// to just add new tags without deleting old ones. /// /// The id of the photo to update. /// An comma-seperated list of tags. /// True if the photo was updated successfully. public bool PhotosSetTags(string photoId, string tags) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.setTags"); parameters.Add("photo_id", photoId); parameters.Add("tags", tags); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } #endregion #region [ Photos Comments ] /// /// Gets a list of comments for a photo. /// /// The id of the photo to return the comments for. /// An array of objects. public Comment[] PhotosCommentsGetList(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.comments.getList"); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return PhotoComments.GetComments(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } /// /// Adds a new comment to a photo. /// /// The ID of the photo to add the comment to. /// The text of the comment. Can contain some HTML. /// The new ID of the created comment. public string PhotosCommentsAddComment(string photoId, string commentText) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.comments.addComment"); parameters.Add("photo_id", photoId); parameters.Add("comment_text", commentText); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { XmlNode node = response.AllElements[0]; if( node.Attributes.GetNamedItem("id") != null ) return node.Attributes.GetNamedItem("id").Value; else throw new FlickrException(9001, "Comment ID not found"); } else { throw new FlickrException(response.Error); } } /// /// Deletes a comment from a photo. /// /// The ID of the comment to delete. public void PhotosCommentsDeleteComment(string commentId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.comments.deleteComment"); parameters.Add("comment_id", commentId); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } /// /// Edits a comment. /// /// The ID of the comment to edit. /// The new text for the comment. public void PhotosCommentsEditComment(string commentId, string commentText) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.comments.editComment"); parameters.Add("comment_id", commentId); parameters.Add("comment_text", commentText); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } #endregion #region [ Photosets ] /// /// Add a photo to a photoset. /// /// The ID of the photoset to add the photo to. /// The ID of the photo to add. public void PhotosetsAddPhoto(string photosetId, string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.addPhoto"); parameters.Add("photoset_id", photosetId); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } /// /// Creates a blank photoset, with a title and a primary photo (minimum requirements). /// /// The title of the photoset. /// The ID of the photo which will be the primary photo for the photoset. This photo will also be added to the set. /// The that is created. public Photoset PhotosetsCreate(string title, string primaryPhotoId) { return PhotosetsCreate(title, null, primaryPhotoId); } /// /// Creates a blank photoset, with a title, description and a primary photo. /// /// The title of the photoset. /// THe description of the photoset. /// The ID of the photo which will be the primary photo for the photoset. This photo will also be added to the set. /// The that is created. public Photoset PhotosetsCreate(string title, string description, string primaryPhotoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.create"); parameters.Add("title", title); parameters.Add("primary_photo_id", primaryPhotoId); parameters.Add("description", description); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photoset; } else { throw new FlickrException(response.Error); } } /// /// Deletes the specified photoset. /// /// The ID of the photoset to delete. /// Returns true when the photoset has been deleted. public bool PhotosetsDelete(string photosetId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.delete"); parameters.Add("photoset_id", photosetId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } /// /// Updates the title and description for a photoset. /// /// The ID of the photoset to update. /// The new title for the photoset. /// The new description for the photoset. /// Returns true when the photoset has been updated. public bool PhotosetsEditMeta(string photosetId, string title, string description) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.editMeta"); parameters.Add("photoset_id", photosetId); parameters.Add("title", title); parameters.Add("description", description); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } /// /// Sets the photos for a photoset. /// /// /// Will remove any previous photos from the photoset. /// The order in thich the photoids are given is the order they will appear in the /// photoset page. /// /// The ID of the photoset to update. /// The ID of the new primary photo for the photoset. /// An array of photo IDs. /// Returns true when the photoset has been updated. public bool PhotosetsEditPhotos(string photosetId, string primaryPhotoId, string[] photoIds) { return PhotosetsEditPhotos(photosetId, primaryPhotoId, string.Join(",", photoIds)); } /// /// Sets the photos for a photoset. /// /// /// Will remove any previous photos from the photoset. /// The order in thich the photoids are given is the order they will appear in the /// photoset page. /// /// The ID of the photoset to update. /// The ID of the new primary photo for the photoset. /// An comma seperated list of photo IDs. /// Returns true when the photoset has been updated. public bool PhotosetsEditPhotos(string photosetId, string primaryPhotoId, string photoIds) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.editPhotos"); parameters.Add("photoset_id", photosetId); parameters.Add("primary_photo_id", primaryPhotoId); parameters.Add("photo_ids", photoIds); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { throw new FlickrException(response.Error); } } /// /// Gets the context of the specified photo within the photoset. /// /// The photo id of the photo in the set. /// The id of the set. /// of the specified photo. public Context PhotosetsGetContext(string photoId, string photosetId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.getContext"); parameters.Add("photo_id", photoId); parameters.Add("photoset_id", photosetId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { Context c = new Context(); c.Count = response.ContextCount.Count; c.NextPhoto = response.ContextNextPhoto; c.PreviousPhoto = response.ContextPrevPhoto; return c; } else { throw new FlickrException(response.Error); } } /// /// Gets the information about a photoset. /// /// The ID of the photoset to return information for. /// A instance. public Photoset PhotosetsGetInfo(string photosetId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.getInfo"); parameters.Add("photoset_id", photosetId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photoset; } else { throw new FlickrException(response.Error); } } /// /// Gets a list of the currently authenticated users photosets. /// /// A instance containing a collection of photosets. public Photosets PhotosetsGetList() { return PhotosetsGetList(null); } /// /// Gets a list of the specified users photosets. /// /// The ID of the user to return the photosets of. /// A instance containing a collection of photosets. public Photosets PhotosetsGetList(string userId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.getList"); if( userId != null ) parameters.Add("user_id", userId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photosets; } else { throw new FlickrException(response.Error); } } /// /// Gets a collection of photos for a photoset. /// /// The ID of the photoset to return photos for. /// An array of instances. public Photo[] PhotosetsGetPhotos(string photosetId) { return PhotosetsGetPhotos(photosetId, PhotoSearchExtras.All, PrivacyFilter.None); } /// /// Gets a collection of photos for a photoset. /// /// The ID of the photoset to return photos for. /// The privacy filter to search on. /// An array of instances. public Photo[] PhotosetsGetPhotos(string photosetId, PrivacyFilter privacyFilter) { return PhotosetsGetPhotos(photosetId, PhotoSearchExtras.All, privacyFilter); } /// /// Gets a collection of photos for a photoset. /// /// The ID of the photoset to return photos for. /// The extras to return for each photo. /// An array of instances. public Photo[] PhotosetsGetPhotos(string photosetId, PhotoSearchExtras extras) { return PhotosetsGetPhotos(photosetId, extras, PrivacyFilter.None); } /// /// Gets a collection of photos for a photoset. /// /// The ID of the photoset to return photos for. /// The extras to return for each photo. /// The privacy filter to search on. /// An array of instances. public Photo[] PhotosetsGetPhotos(string photosetId, PhotoSearchExtras extras, PrivacyFilter privacyFilter) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.getPhotos"); parameters.Add("photoset_id", photosetId); if( extras != PhotoSearchExtras.None ) parameters.Add("extras", Utils.ExtrasToString(extras)); if( privacyFilter != PrivacyFilter.None ) parameters.Add("privacy_filter", privacyFilter.ToString("d")); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { if( response.Photoset.PhotoCollection == null ) return new Photo[0]; if( response.Photoset.OwnerId != null && response.Photoset.OwnerId.Length > 0 ) { foreach(Photo p in response.Photoset.PhotoCollection) { p.UserId = response.Photoset.OwnerId; } } return response.Photoset.PhotoCollection; } else { throw new FlickrException(response.Error); } } /// /// Changes the order of your photosets. /// /// An array of photoset IDs, /// ordered with the set to show first, first in the list. /// Any set IDs not given in the list will be set to appear at the end of the list, ordered by their IDs. public void PhotosetsOrderSets(string[] photosetIds) { PhotosetsOrderSets(string.Join(",", photosetIds)); } /// /// Changes the order of your photosets. /// /// A comma delimited list of photoset IDs, /// ordered with the set to show first, first in the list. /// Any set IDs not given in the list will be set to appear at the end of the list, ordered by their IDs. public void PhotosetsOrderSets(string photosetIds) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.orderSets"); parameters.Add("photosetIds", photosetIds); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } /// /// Removes a photo from a photoset. /// /// /// An exception will be raised if the photo is not in the set. /// /// The ID of the photoset to remove the photo from. /// The ID of the photo to remove. public void PhotosetsRemovePhoto(string photosetId, string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.removePhoto"); parameters.Add("photoset_id", photosetId); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } #endregion #region [ Photoset Comments ] /// /// Gets a list of comments for a photoset. /// /// The id of the photoset to return the comments for. /// An array of objects. public Comment[] PhotosetsCommentsGetList(string photosetId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.comments.getList"); parameters.Add("photoset_id", photosetId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return PhotoComments.GetComments(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } /// /// Adds a new comment to a photoset. /// /// The ID of the photoset to add the comment to. /// The text of the comment. Can contain some HTML. /// The new ID of the created comment. public string PhotosetsCommentsAddComment(string photosetId, string commentText) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.comments.addComment"); parameters.Add("photoset_id", photosetId); parameters.Add("comment_text", commentText); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { XmlNode node = response.AllElements[0]; if( node.Attributes.GetNamedItem("id") != null ) return node.Attributes.GetNamedItem("id").Value; else throw new FlickrException(9001, "Comment ID not found"); } else { throw new FlickrException(response.Error); } } /// /// Deletes a comment from a photoset. /// /// The ID of the comment to delete. public void PhotosetsCommentsDeleteComment(string commentId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.comments.deleteComment"); parameters.Add("comment_id", commentId); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } /// /// Edits a comment. /// /// The ID of the comment to edit. /// The new text for the comment. public void PhotosetsCommentsEditComment(string commentId, string commentText) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photosets.comments.editComment"); parameters.Add("comment_id", commentId); parameters.Add("comment_text", commentText); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } #endregion #region [ Tags ] /// /// Get the tag list for a given photo. /// /// The id of the photo to return tags for. /// An instance of the class containing only the property. public PhotoInfo TagsGetListPhoto(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.tags.getListPhoto"); parameters.Add("api_key", _apiKey); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.PhotoInfo; } else { throw new FlickrException(response.Error); } } /// /// Get the tag list for a given user (or the currently logged in user). /// /// An array of objects. public Tag[] TagsGetListUser() { return TagsGetListUser(null); } /// /// Get the tag list for a given user (or the currently logged in user). /// /// The NSID of the user to fetch the tag list for. If this argument is not specified, the currently logged in user (if any) is assumed. /// An array of objects. public Tag[] TagsGetListUser(string userId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.tags.getListUser"); if( userId != null && userId.Length > 0 ) parameters.Add("user_id", userId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { XmlNodeList nodes = response.AllElements[0].SelectNodes("//tag"); Tag[] tags = new Tag[nodes.Count]; for(int i = 0; i < tags.Length; i++) { tags[i] = new Tag(nodes[i]); } return tags; } else { throw new FlickrException(response.Error); } } /// /// Get the popular tags for a given user (or the currently logged in user). /// /// An array of objects. public Tag[] TagsGetListUserPopular() { return TagsGetListUserPopular(null, 0); } /// /// Get the popular tags for a given user (or the currently logged in user). /// /// Number of popular tags to return. defaults to 10 when this argument is not present. /// An array of objects. public Tag[] TagsGetListUserPopular(int count) { return TagsGetListUserPopular(null, count); } /// /// Get the popular tags for a given user (or the currently logged in user). /// /// The NSID of the user to fetch the tag list for. If this argument is not specified, the currently logged in user (if any) is assumed. /// An array of objects. public Tag[] TagsGetListUserPopular(string userId) { return TagsGetListUserPopular(userId, 0); } /// /// Get the popular tags for a given user (or the currently logged in user). /// /// The NSID of the user to fetch the tag list for. If this argument is not specified, the currently logged in user (if any) is assumed. /// Number of popular tags to return. defaults to 10 when this argument is not present. /// An array of objects. public Tag[] TagsGetListUserPopular(string userId, long count) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.tags.getListUserPopular"); if( userId != null ) parameters.Add("user_id", userId); if( count > 0 ) parameters.Add("count", count.ToString()); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { XmlNodeList nodes = response.AllElements[0].SelectNodes("//tag"); Tag[] tags = new Tag[nodes.Count]; for(int i = 0; i < tags.Length; i++) { tags[i] = new Tag(nodes[i]); } return tags; } else { throw new FlickrException(response.Error); } } /// /// Returns a list of tags 'related' to the given tag, based on clustered usage analysis. /// /// The tag to fetch related tags for. /// An array of objects. public Tag[] TagsGetRelated(string tag) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.tags.getRelated"); parameters.Add("api_key", _apiKey); parameters.Add("tag", tag); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { XmlNodeList nodes = response.AllElements[0].SelectNodes("//tag"); Tag[] tags = new Tag[nodes.Count]; for(int i = 0; i < tags.Length; i++) { tags[i] = new Tag(nodes[i]); } return tags; } else { throw new FlickrException(response.Error); } } #endregion #region [ Transform ] /// /// Rotates a photo on Flickr. /// /// /// Does not rotate the original photo. /// /// The ID of the photo. /// The number of degrees to rotate by. Valid values are 90, 180 and 270. public void TransformRotate(string photoId, int degrees) { if( photoId == null ) throw new ArgumentNullException("photoId"); if( degrees != 90 && degrees != 180 && degrees != 270 ) throw new ArgumentException("Must be 90, 180 or 270", "degrees"); Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.transform.rotate"); parameters.Add("photo_id", photoId); parameters.Add("degrees", degrees.ToString("0")); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } #endregion #region [ Geo ] /// /// Returns the location data for a give photo. /// /// The ID of the photo to return the location information for. /// Returns null if the photo has no location information, otherwise returns the location information. public PhotoLocation PhotosGeoGetLocation(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.geo.getLocation"); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.PhotoInfo.Location; } else { if( response.Error.Code == 2 ) return null; else throw new FlickrException(response.Error); } } /// /// Sets the geo location for a photo. /// /// The ID of the photo to set to location for. /// The latitude of the geo location. A double number ranging from -180.00 to 180.00. Digits beyond 6 decimal places will be truncated. /// The longitude of the geo location. A double number ranging from -180.00 to 180.00. Digits beyond 6 decimal places will be truncated. public void PhotosGeoSetLocation(string photoId, double latitude, double longitude) { PhotosGeoSetLocation(photoId, latitude, longitude, GeoAccuracy.None); } /// /// Sets the geo location for a photo. /// /// The ID of the photo to set to location for. /// The latitude of the geo location. A double number ranging from -180.00 to 180.00. Digits beyond 6 decimal places will be truncated. /// The longitude of the geo location. A double number ranging from -180.00 to 180.00. Digits beyond 6 decimal places will be truncated. /// The accuracy of the photos geo location. public void PhotosGeoSetLocation(string photoId, double latitude, double longitude, GeoAccuracy accuracy) { System.Globalization.NumberFormatInfo nfi = System.Globalization.NumberFormatInfo.InvariantInfo; Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.geo.setLocation"); parameters.Add("photo_id", photoId); parameters.Add("lat", latitude.ToString(nfi)); parameters.Add("lon", longitude.ToString(nfi)); if( accuracy != GeoAccuracy.None ) parameters.Add("accuracy", ((int)accuracy).ToString()); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } /// /// Removes Location information. /// /// The photo ID of the photo to remove information from. /// Returns true if the location information as found and removed. Returns false if no photo information was found. public bool PhotosGeoRemoveLocation(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.geo.removeLocation"); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { return true; } else { if( response.Error.Code == 2 ) return false; else throw new FlickrException(response.Error); } } /// /// Gets a list of photos that do not contain geo location information. /// /// A list of photos that do not contain location information. public Photos PhotosGetWithoutGeoData() { PartialSearchOptions options = new PartialSearchOptions(); return PhotosGetWithoutGeoData(options); } /// /// Gets a list of photos that do not contain geo location information. /// /// A limited set of options are supported. /// A list of photos that do not contain location information. public Photos PhotosGetWithoutGeoData(PartialSearchOptions options) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getWithoutGeoData"); Utils.PartialOptionsIntoArray(options, parameters); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } /// /// Gets a list of photos that do not contain geo location information. /// /// A limited set of options are supported. /// Unsupported arguments are ignored. /// See http://www.flickr.com/services/api/flickr.photos.getWithGeoData.html for supported properties. /// A list of photos that do not contain location information. [Obsolete("Use the PartialSearchOptions instead")] public Photos PhotosGetWithoutGeoData(PhotoSearchOptions options) { PartialSearchOptions newOptions = new PartialSearchOptions(options); return PhotosGetWithoutGeoData(newOptions); } /// /// Gets a list of photos that contain geo location information. /// /// /// Note, this method doesn't actually return the location information with the photos, /// unless you specify the option in the extras parameter. /// /// A list of photos that contain Location information. public Photos PhotosGetWithGeoData() { PartialSearchOptions options = new PartialSearchOptions(); return PhotosGetWithGeoData(options); } /// /// Gets a list of photos that contain geo location information. /// /// /// Note, this method doesn't actually return the location information with the photos, /// unless you specify the option in the extras parameter. /// /// A limited set of options are supported. /// Unsupported arguments are ignored. /// See http://www.flickr.com/services/api/flickr.photos.getWithGeoData.html for supported properties. /// A list of photos that contain Location information. [Obsolete("Use the new PartialSearchOptions instead")] public Photos PhotosGetWithGeoData(PhotoSearchOptions options) { PartialSearchOptions newOptions = new PartialSearchOptions(options); return PhotosGetWithGeoData(newOptions); } /// /// Gets a list of photos that contain geo location information. /// /// /// Note, this method doesn't actually return the location information with the photos, /// unless you specify the option in the extras parameter. /// /// The options to filter/sort the results by. /// A list of photos that contain Location information. public Photos PhotosGetWithGeoData(PartialSearchOptions options) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.getWithGeoData"); Utils.PartialOptionsIntoArray(options, parameters); FlickrNet.Response response = GetResponseNoCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Photos; } else { throw new FlickrException(response.Error); } } /// /// Get permissions for a photo. /// /// The id of the photo to get permissions for. /// An instance of the class containing the permissions of the specified photo. public GeoPermissions PhotosGeoGetPerms(string photoId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.geo.getPerms"); parameters.Add("photo_id", photoId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return new GeoPermissions(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } /// /// Set the permission for who can see geotagged photos on Flickr. /// /// The ID of the photo permissions to update. /// /// /// /// public void PhotosGeoSetPerms(string photoId, bool IsPublic, bool IsContact, bool IsFamily, bool IsFriend) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.photos.geo.setPerms"); parameters.Add("photo_id", photoId); parameters.Add("is_public", IsPublic?"1":"0"); parameters.Add("is_contact", IsContact?"1":"0"); parameters.Add("is_friend", IsFriend?"1":"0"); parameters.Add("is_family", IsFamily?"1":"0"); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return; } else { throw new FlickrException(response.Error); } } #endregion #region [ Tests ] /// /// Can be used to call unsupported methods in the Flickr API. /// /// /// Use of this method is not supported. /// The way the FlickrNet API Library works may mean that some methods do not return an expected result /// when using this method. /// /// The method name, e.g. "flickr.test.null". /// A list of parameters. Note, api_key is added by default and is not included. Can be null. /// An array of instances which is the expected response. public XmlElement[] TestGeneric(string method, NameValueCollection parameters) { Hashtable _parameters = new Hashtable(); if( parameters != null ) { foreach(string key in parameters.AllKeys) { _parameters.Add(key, parameters[key]); } } _parameters.Add("method", method); FlickrNet.Response response = GetResponseNoCache(_parameters); if( response.Status == ResponseStatus.OK ) { return response.AllElements; } else { throw new FlickrException(response.Error); } } /// /// Runs the flickr.test.echo method and returned an array of items. /// /// The parameter to pass to the method. /// The value to pass to the method with the parameter. /// An array of items. /// /// The APi Key has been removed from the returned array and will not be shown. /// /// /// /// XmlElement[] elements = flickr.TestEcho("&param=value"); /// foreach(XmlElement element in elements) /// { /// if( element.Name = "method" ) /// Console.WriteLine("Method = " + element.InnerXml); /// if( element.Name = "param" ) /// Console.WriteLine("Param = " + element.InnerXml); /// } /// /// public XmlElement[] TestEcho(string echoParameter, string echoValue) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.test.echo"); parameters.Add("api_key", _apiKey); if( echoParameter != null && echoParameter.Length > 0 ) { parameters.Add(echoParameter, echoValue); } FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { // Remove the api_key element from the array. XmlElement[] elements = new XmlElement[response.AllElements.Length - 1]; int c = 0; foreach(XmlElement element in response.AllElements) { if(element.Name != "api_key" ) elements[c++] = element; } return elements; } else { throw new FlickrException(response.Error); } } /// /// Test the logged in state of the current Filckr object. /// /// The object containing the username and userid of the current user. public FoundUser TestLogin() { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.test.login"); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return new FoundUser(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } #endregion #region [ Urls ] /// /// Returns the url to a group's page. /// /// The NSID of the group to fetch the url for. /// An instance of the class containing the URL of the group page. public Uri UrlsGetGroup(string groupId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.urls.getGroup"); parameters.Add("api_key", _apiKey); parameters.Add("group_id", groupId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { if( response.AllElements[0] != null && response.AllElements[0].Attributes["url"] != null ) return new Uri(response.AllElements[0].Attributes["url"].Value); else return null; } else { throw new FlickrException(response.Error); } } /// /// Returns the url to a user's photos. /// /// An instance of the class containing the URL for the users photos. public Uri UrlsGetUserPhotos() { return UrlsGetUserPhotos(null); } /// /// Returns the url to a user's photos. /// /// The NSID of the user to fetch the url for. If omitted, the calling user is assumed. /// The URL of the users photos. public Uri UrlsGetUserPhotos(string userId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.urls.getUserPhotos"); if( userId != null && userId.Length > 0 ) parameters.Add("user_id", userId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { if( response.AllElements[0] != null && response.AllElements[0].Attributes["url"] != null ) return new Uri(response.AllElements[0].Attributes["url"].Value); else return null; } else { throw new FlickrException(response.Error); } } /// /// Returns the url to a user's profile. /// /// An instance of the class containing the URL for the users profile. public Uri UrlsGetUserProfile() { return UrlsGetUserProfile(null); } /// /// Returns the url to a user's profile. /// /// The NSID of the user to fetch the url for. If omitted, the calling user is assumed. /// An instance of the class containing the URL for the users profile. public Uri UrlsGetUserProfile(string userId) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.urls.getUserProfile"); if( userId != null && userId.Length > 0 ) parameters.Add("user_id", userId); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { if( response.AllElements[0] != null && response.AllElements[0].Attributes["url"] != null ) return new Uri(response.AllElements[0].Attributes["url"].Value); else return null; } else { throw new FlickrException(response.Error); } } /// /// Returns a group NSID, given the url to a group's page or photo pool. /// /// The url to the group's page or photo pool. /// The ID of the group at the specified URL on success, a null reference (Nothing in Visual Basic) if the group cannot be found. public string UrlsLookupGroup(string urlToFind) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.urls.lookupGroup"); parameters.Add("api_key", _apiKey); parameters.Add("url", urlToFind); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { if( response.AllElements[0] != null && response.AllElements[0].Attributes["id"] != null ) { return response.AllElements[0].Attributes["id"].Value; } else { return null; } } else { if( response.Error.Code == 1 ) return null; else throw new FlickrException(response.Error); } } /// /// Returns a user NSID, given the url to a user's photos or profile. /// /// Thr url to the user's profile or photos page. /// An instance of the class containing the users ID and username. public FoundUser UrlsLookupUser(string urlToFind) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.urls.lookupUser"); parameters.Add("api_key", _apiKey); parameters.Add("url", urlToFind); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return new FoundUser(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } #endregion #region [ Reflection ] /// /// Gets an array of supported method names for Flickr. /// /// /// Note: Not all methods might be supported by the FlickrNet Library. /// public string[] ReflectionGetMethods() { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.reflection.getMethods"); parameters.Add("api_key", _apiKey); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return Methods.GetMethods(response.AllElements[0]); } else { throw new FlickrException(response.Error); } } /// /// Gets the method details for a given method. /// /// The name of the method to retrieve. /// Returns a instance for the given method name. public Method ReflectionGetMethodInfo(string methodName) { Hashtable parameters = new Hashtable(); parameters.Add("method", "flickr.reflection.getMethodInfo"); parameters.Add("api_key", _apiKey); parameters.Add("method_name", methodName); FlickrNet.Response response = GetResponseCache(parameters); if( response.Status == ResponseStatus.OK ) { return response.Method; } else { throw new FlickrException(response.Error); } } #endregion #region [ MD5 Hash ] private static string Md5Hash(string unhashed) { System.Security.Cryptography.MD5CryptoServiceProvider csp = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(unhashed); byte[] hashedBytes = csp.ComputeHash(bytes, 0, bytes.Length); return BitConverter.ToString(hashedBytes).Replace("-", "").ToLower(); } #endregion } }