0
我无法获得Google API PageSpeed Insights截图,他们提供的网站在击中API时。我看过其他例子,但似乎没有一个适合我。谷歌页面洞察api截图 - Laravel
这是我的控制器:
public function fetch() {
$key = env('GOOGLE_ANALYTICS_KEY');
$website = request('website_url');
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=http://' .$website. '&key=' . $key . '&screenshot=true');
if ($res->getStatusCode() == 200) {
$result = json_decode($res->getBody());
$data = str_replace('_','/',$result->screenshot->data);
$data = str_replace('-','+',$data);
$decoded = base64_decode($data);
return view('api.index', compact('result', 'decoded'));
} else {
return redirect()->back();
}
}
我尝试调用它的前端是这样的:
<img src="data:image/jpeg;base64,'{{ $decoded }}">
// And like this
<img src="{{ $decoded }}">
但仅仅得到一个空的src = “”
你的第一个''标记看起来像它最后缺少一个''''。 – ceejayoz
没看见。我修好了它。尽管如此,它仍然是空虚的。 – David
查看源代码时是否将数据输出到页面?你为什么要替换数据中的'_'和'-'? – ceejayoz