SDK and Code Examples
support@screenshotone.com
.Go
It takes minutes to start taking screenshots in Go. Just sign up to get access and secret keys, import the client, and you are ready to go.
Installation
go get github.com/screenshotone/gosdk
Usage
Import the library:
import screenshots "github.com/screenshotone/gosdk"
Generate a screenshot URL without executing request:
client, err := screenshots.NewClient("IVmt2ghj9TG_jQ", "Sxt94yAj9aQSgg")
if err != nil {
// ...
}
options := screenshots.NewTakeOptions("https://scalabledeveloper.com").
Format("png").
FullPage(true).
DeviceScaleFactor(2).
BlockAds(true).
BlockTrackers(true)
u, err := client.GenerateTakeURL(options)
if err != nil {
// ...
}
fmt.Println(u.String())
// Output: https://api.screenshotone.com/take?access_key=IVmt2ghj9TG_jQ&block_ads=true&block_trackers=true&device_scale_factor=2&format=png&full_page=true&url=https%3A%2F%2Fscalabledeveloper.com&signature=85aabf7ac251563ec6158ef6839dd019bb79ce222cc85288a2e8cea0291a824e
Take a screenshot and save the image in the file:
client, err := screenshots.NewClient("IVmt2ghj9TG_jQ", "Sxt94yAj9aQSgg")
if err != nil {
// ...
}
options := screenshots.NewTakeOptions("https://example.com").
Format("png").
FullPage(true).
DeviceScaleFactor(2).
BlockAds(true).
BlockTrackers(true)
image, err := client.Take(context.TODO(), options)
if err != nil {
// ...
}
defer image.Close()
out, err := os.Create("example.png")
if err != nil {
// ...
}
defer out.Close()
io.Copy(out, image)
Java
It takes minutes to start taking screenshots in Java. Just sign up to get access and secret keys, import the client, and you are ready to go.
Installation
Add dependency to your pom.xml
:
<dependencies>
<dependency>
<groupId>com.screenshotone.jsdk</groupId>
<artifactId>screenshotone-api-jsdk</artifactId>
<version>[1.0.0,2.0.0)</version>
</dependency>
</dependencies>
Usage
Generate a screenshot URL without executing request:
import com.screenshotone.jsdk.Client;
import com.screenshotone.jsdk.TakeOptions;
public class App {
public static void main(String[] args) throws Exception {
final Client client = Client.withKeys("IVmt2ghj9TG_jQ", "Sxt94yAj9aQSgg");
TakeOptions takeOptions = TakeOptions.url("https://scalabledeveloper.com")
.fullPage(true)
.deviceScaleFactor(1)
.viewportHeight(1200)
.viewportWidth(1200)
.format("png")
.omitBackground(true);
final String url = client.generateTakeUrl(takeOptions);
System.out.println(url);
// Output: https://api.screenshotone.com/take?access_key=IVmt2ghj9TG_jQ&device_scale_factor=1&format=png&full_page=true&omit_background=true&url=https%3A%2F%2Fscalabledeveloper.com&viewport_height=1200&viewport_width=1200&signature=3c0c5543599067322e8c84470702330e3687c6a08eef6b7311b71c32d04e1bd5
}
}
Usually you generate URL to place it inside the image tag () or to share it.
Take a screenshot and save the image in the file:
import com.screenshotone.jsdk.Client;
import com.screenshotone.jsdk.TakeOptions;
import java.io.File;
import java.nio.file.Files;
public class App {
public static void main(String[] args) throws Exception {
final Client client = Client.withKeys("IVmt2ghj9TG_jQ", "Sxt94yAj9aQSgg");
TakeOptions takeOptions = TakeOptions.url("https://scalabledeveloper.com")
.fullPage(true)
.deviceScaleFactor(1)
.viewportHeight(1200)
.viewportWidth(1200)
.format("png")
.omitBackground(true);
final byte[] image = client.take(takeOptions);
Files.write(new File("./example.png").toPath(), image);
}
}
JavaScript and TypeScript (Node.js)
Installation
Run the next command to install the JavaScript and TypeScript Node.js SDK to take screenshots:
npm install screenshotone-api-sdk --save
Usage
Don’t forget to sign up to get access and secret keys.
Generate a screenshot URL without executing the request. Or download the screenshot. It is up to you:
import * as fs from 'fs';
import * as screenshotone from 'screenshotone-api-sdk';
// create API client
const client = new screenshotone.Client("<access key>", "<secret key>");
// set up options
const options = screenshotone.TakeOptions
.url("https://example.com")
.delay(3)
.blockAds(true);
// generate URL
const url = client.generateTakeURL(options);
console.log(url);
// expected output: https://api.screenshotone.com/take?url=https%3A%2F%2Fexample.com&delay=3&block_ads=true&access_key=%3Caccess+key%3E&signature=7f3419ece2c53ed2c7923c7d5deef290d662c3643822bf69ec8259ce10b3ea61
// or download the screenshot
const imageBlob = await client.take(options);
const buffer = Buffer.from(await imageBlob.arrayBuffer());
fs.writeFileSync("example.png", buffer)
// the screenshot is store in the example.png file
PHP
Installation
Run the next command to install the PHP SDK to take screenshots:
composer require screenshotone/sdk:^1.0
Usage
Don’t forget to sign up to get access and secret keys.
Generate a screenshot URL without executing the request. Or download the screenshot. It is up to you:
<?php
use ScreenshotOne\Sdk\Client;
use ScreenshotOne\Sdk\TakeOptions;
$client = new Client('<access key>', '<secret key>');
$options = TakeOptions::url("https://example.com")
->fullPage(true)
->delay(2)
->geolocationLatitude(48.857648)
->geolocationLongitude(2.294677)
->geolocationAccuracy(50);
$url = $client->generateTakeUrl($options);
echo $url.PHP_EOL;
// expected output: https://api.screenshotone.com/take?url=https%3A%2F%2Fexample.com...
$image = $client->take($options);
file_put_contents('example.png', $image);
// the screenshot is stored in the example.png file
Ruby
Installation
Update your Gemfile:
gem 'screenshotone'
Then execute:
bundle install
Usage
Don’t forget to sign up to get access and secret keys.
Generate a screenshot URL without executing the request. Or download the screenshot. It is up to you:
# If you don't need to add a signature
client = ScreenshotOne::Client.new('my_access_key')
# If you do need to add a signature
client = ScreenshotOne::Client.new('my_access_key', 'my_secret_key')
# You can set any available option, in a camel_case format, for example:
options = ScreenshotOne::TakeOptions.new(url: 'https://example.com').
full_page(true).
delay(2).
geolocation_latitude(48.857648).
geolocation_longitude(2.294677).
geolocation_accuracy(50)
# Verify all the parameters are valid (we will validate the parameters that should be
# numeric, booleans or that accept only certain values)
options.valid?
=> true
# To simply get the final url:
client.generate_take_url(options)
=> "https://api.screenshotone.com/take?url=https%3A%2F%2Fexample.com..."
# To actually get the image (the response body of a request to the previous url)
client.take(options)
=> "\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xFF\..."
Python
Installation
Run the next command to install the Python SDK to take screenshots:
pip install screenshotone
Usage
Don’t forget to sign up to get access and secret keys.
Generate a screenshot URL without executing the request. Or download the screenshot. It is up to you:
import shutil
from screenshotone import Client, TakeOptions
# create API client
client = Client('<your access key>', '<your secret key>')
# set up options
options = (TakeOptions.url('https://screenshotone.com')
.format("png")
.viewport_width(1024)
.viewport_height(768)
.block_cookie_banners(True)
.block_chats(True))
# generate the screenshot URL and share it with a user
url = client.generate_take_url(options)
# expected output: https://api.screenshotone.com/take?url=https%3A%2F%2Fscreenshotone.com&viewport_width=1024&viewport_height=768&block_cookie_banners=True&block_chats=True&access_key=<your access key>&signature=6afc9417a523788580fa01a9f668ea82c78a9d2b41441d2a696010bf2743170f
# or render a screenshot and download the image as stream
image = client.take(options)
# store the screenshot the example.png file
with open('example.png', 'wb') as result_file:
shutil.copyfileobj(image, result_file)
C# (.NET)
Installation
Add the library via nuget using the package manager console:
PM> Install-Package ScreenshotOne.dotnetsdk
Or from the .NET CLI as:
dotnet add package ScreenshotOne.dotnetsdk
Usage
Don’t forget to sign up to get access and secret keys.
Generate a screenshot URL without executing request:
var client = new Client("<access key>", "<secret key>");
var options = TakeOptions.Url("https://www.amazon.com")
.FullPage(true)
.Format(Format.PNG)
.BlockCookieBanners(true);
var url = client.GenerateTakeUrl(options);
// url = https://api.screenshotone.com/take?url=https%3A%2F%2Fwww.amazon.com&full_page=true&format=png&block_cookie_banners=true&access_key=_OzqMIjpCw-ARQ&signature=8a08e62d13a5c3490fda0734b6707791d3decc9ab9ba41e8cc045288a39db502
Take a screenshot and save the image in the file:
var client = new Client("<access key>", "<secret key>");
var options = TakeOptions.Url("https://www.google.com")
.FullPage(true)
.Format(Format.PNG)
.BlockCookieBanners(true);
var bytes = await client.Take(options);
File.WriteAllBytes(@"c:\temp\example.png", bytes);