SDK and Code Examples

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