0

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
yushi
  • 43
  • 4
  • 1
    Start by checking what response you actually got. https://stackoverflow.com/a/6041020/1427878 – CBroe Aug 29 '23 at 06:06

1 Answers1

-1

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.

  • 1
    See [answer] - don't just dump code, _explain_ your answer and _why_ it helps. That is much more useful for others, rather than just having to trust that everything you've written is actually relevant or meaningful to them. – ADyson Aug 29 '23 at 08:40