[ "method" => "GET", "header" => "Authorization: Describe api here" ] ]; $context = stream_context_create($opts); $scree" /> [ "method" => "GET", "header" => "Authorization: Describe api here" ] ]; $context = stream_context_create($opts); $scree" /> [ "method" => "GET", "header" => "Authorization: Describe api here" ] ]; $context = stream_context_create($opts); $scree"/>

I'm using the screendot API, but the screenshot is not output

47 Views Asked by At

php

<?php

$opts = [
    "http" => [
        "method" => "GET",
        "header" => "Authorization: Describe api here"
    ]
];

$context = stream_context_create($opts);

$screenshot = file_get_contents("https://screendot.io/api/standard?url=https://www.google.com", false, $context);

echo $screenshot

?>

I am trying to take a screenshot using the screendot API, but the screenshot is not output. I'm using the sample code as is, but it won't take. Please help me.

1

There are 1 best solutions below

1
Ritesh Hirapara On BEST ANSWER

Try below code. it will work for you.

$apiKey = '*********';

$url = "https://screendot.io/api/standard?url=https://www.test.com";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $apiKey"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$screenshot = curl_exec($ch);

if ($screenshot === false) {
    echo "cURL Error: " . curl_error($ch);
} else {
    header("Content-Type: image/png");
    echo $screenshot;
}

curl_close($ch);

If you'll face same issue give me the error log in comment.