As well as the basic screenshot functionality the GrabzIt ASP.NET API allows developers, to do many other tasks including mobile screenshots and custom watermarks. One common task is to check the status of existing screenshots and set the cookies that GrabzIt will use to take screenshots for the developer.
Sometimes a application may need to check the status of a screenshot, perhaps to see if it has been taken or to check if it is still cached.
//The client should be stored somewhere and reused! GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret", client); ScreenShotStatus status = await grabzIt.GetStatusAsync(screenShotId); if (status.Processing) { // screenshot has not yet been processed } if (status.Cached) { // screenshot is still cached by GrabzIt } string error; if (status.Expired) { // screenshot is no longer on GrabzIt // Perhaps output status message? error = status.Message; }
Some websites control functionality through cookies. GrabzIt allows you to set your own developer definied cookies in the following way.
//The client should be stored somewhere and reused! GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret", client); // gets an array of cookies for google.com GrabzItCookie[] cookies = await grabzIt.GetCookiesAsync("google.com"); # sets a cookie for the google.com domain await grabzIt.SetCookieAsync("MyCookie", "google.com", "Any Value You Like"); # deletes the previously set cookie await grabzIt.DeleteCookieAsync("MyCookie", "google.com");
Note that the delete cookie method will delete all cookies with the same name and domain.
While its recommended that a capture is downloaded to a web server before being used. It is possible to display any type of capture in a user's browser without downloading it onto your web server first.
Once the capture has completed you can send the bytes of the capture returned by the SaveTo method to the response along with the correct mime type.
//The client should be stored somewhere and reused! GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret", client); grabzIt.URLToImage("https://www.tesla.com"); GrabzItFile capture = await grabzIt.SaveToAsync(); if (capture != null) { Response.ContentType = "image/jpeg"; Response.BinaryWrite(capture.Bytes); }
An example of outputting a capture to the response is shown above for the URLToImage
method, but it will work with any of the conversion methods.