0
Google API PageSpeed Insightsのスクリーンショットを取得する際に問題が発生していますが、APIを使用したときにウェブサイトを提供しています。私は他の例を見てきましたが、私にはうまくいかないものはありません。google page insights 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