Skip to content

A Go SDK for the ScreenshotOne.com API to take screenshots of any URL

License

Notifications You must be signed in to change notification settings

screenshotone/gosdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gosdk

Build Go Report Card GoDoc

An official Screenshot API client for Go.

It takes minutes to start taking screenshots. Just sign up to get access and secret keys, import the client, and you are ready to go.

The SDK client is synchronized with the latest screenshot API options.

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 {
    // ...
}

out, err := os.Create("example.png")
if err != nil {
    // ...
}
defer out.Close()

_, err = out.Write(out, image)
if err != nil {
    // ...
}

Tests

To run tests, just execute:

$ go test . 

License

screenshotone/gosdk is released under the MIT license.