Reply to comment

With Caching and Images

This version extends the search method to be able to handle the DayPI search_getRelatedImages API method.

It is Essentially similar to the other calls. The only thing to bear in mind is that you have to use the overloaded version of the Search function which takes a source filter. Without your source filter ID getting images is rather messy. The resulting list of DayImage objects provide properties on most of the relevant XML data. Do bear in mind however that DayImageObject.prop_Credit and DayImageObject.prop_Source.prop_Name may not be the same. For example in the case of Getty Images AFP the credit will be AFP/Getty Images while the Source name will be Getty Images.

To download the image in a given width you could use the following code snippet
public System.Drawing.Image DownloadImage(string ImageID, int Width)
{
System.Net.WebRequest APIRequest;
System.Net.WebResponse APIResponse;
System.Drawing.Image APIImage;
string ImageURL;
ImageURL = string.Concat("http://cache.daylife.com/imageserve/", ImageID, "/", Width.ToString(), "x.jpg");
APIRequest = System.Net.WebRequest.Create(ImageURL);
APIRequest.Timeout = 60000;
APIResponse = APIRequest.GetResponse();
APIImage = System.Drawing.Image.FromStream(APIResponse.GetResponseStream());
APIResponse.Close();
APIResponse = null;
APIRequest = null;
return APIImage;
}

Extract from Usageexample.txt for how to call the search images method.

Query = "Amitabh Bachchan";
DayLifeSearchResult = RequestAPI.Search(DayRequest.enum_DayRequestSearchType.SearchGetRelatedImages, Query, DayRequest.enum_SortOrder.relevance, null, StartDate, EndDate, Offset, Limit, "Your Source Filter ID");

if (DayLifeSearchResult.prop_Success)
{
foreach (DayLifeAPI.Data.DayImage RelatedImage in DayLifeSearchResult.prop_SearchImagesList)
{
// Do something with
//RelatedImage.prop_ImageID;
//RelatedImage.prop_Caption;
//RelatedImage.prop_Credit;
//RelatedImage.prop_Height;
//RelatedImage.prop_ImageDate;
//RelatedImage.prop_ThumbURL;
//RelatedImage.prop_ImageURL;
//RelatedImage.prop_DaylifeURL;
if (RelatedImage.prop_Source.prop_IsValid)
{
////RelatedImage.prop_Source.prop_SourceID
////RelatedImage.prop_Source.prop_Name
////RelatedImage.prop_Source.prop_DaylifeURL
////etc...
}
//etc...
}
}
else
{
MessageBox.Show(string.Concat("Failed, Error Code = ", DayLifeSearchResult.prop_ResultCode));
MessageBox.Show(string.Concat("Failed, Error Message = ", DayLifeSearchResult.prop_ResultMessage));
}

Cheers

Tikiri

Reply

CAPTCHA
This question helps us test whether you are a human visitor and to prevent automated spam submissions.
1 + 12 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.