GrabzIt的API是非常可定制的。 兩個有用的功能是 GrabzIt Node.js API 在創建屏幕截圖和捕獲內容時檢查現有屏幕截圖的狀態並自定義GrabzIt發送的cookie。
要檢查屏幕截圖或捕獲的狀態,請使用 get_status 方法,這將返回一個狀態對象,該狀態對象指示捕獲是否仍在處理中,是否已緩存或已過期。
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); client.get_status(screenShotId, function(error, status){ if (status.processing){ //screenshot has not yet been processed } if (status.cached){ //screenshot is still cached by GrabzIt } if (status.expired){ //screenshot is no longer on GrabzIt //Perhaps output status message? } });
Cookie可以控制許多網站功能。 GrabzIt允許您使用如下所示的cookie方法來設置自己的自定義cookie。
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); //gets an array of cookies for google.com client.get_cookies("google.com", function(error, cookies){ }); //sets a cookie for the google.com domain client.set_cookie("MyCookie", "google.com", {"value":"Any Value You Like"}); //deletes the previously set cookie client.delete_cookie("MyCookie", "google.com");
雖然建議將捕獲的內容使用前下載到Web服務器。 可以在用戶瀏覽器中顯示任何類型的捕獲,而無需先將其下載到Web服務器上。
為此,捕獲完成後,您可以發送由捕獲的oncomplete函數返回的捕獲字節 save_to 方法 響應以及 正確的啞劇類型。 這方面的一個例子 url_to_image
方法如下所示,但可以與任何轉換方法一起使用。
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); client.url_to_image("https://www.tesla.com"); client.save_to(null, function(error, data){ response.writeHead(200, {"Content-Type":"image/jpeg"}); response.write(data); response.end(); });