我使用的是screendot api,但是屏幕截图没有输出

问题描述 投票:0回答:1

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

?>

我尝试使用 screendot api 截取屏幕截图,但屏幕截图未输出。我按原样使用示例代码,但它不会。请帮助我。

php api screenshot file-get-contents
1个回答
0
投票

尝试下面的代码。它会对你有用。

$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);

如果您遇到同样的问题,请在评论中给我错误日志。

© www.soinside.com 2019 - 2024. All rights reserved.