Google "Safe Browsing Lookup API" returns empty array

411 Views Asked by At

I'm trying validate url for comment form.

Then I thought ”Safe Browsing Lookup API” looked good.

However, the following code only returns an empty array in $result.

What can I do to improve this code?

code:

<?php
$api_key = 'xxx';
$url = 'https://safebrowsing.googleapis.com/v4/threatMatches:find?key=' . $api_key;
$data = [
    "client"=>[
      "clientId"      => "yourcompanyname",
      "clientVersion" => "1.5.2"
    ],
    "threatInfo"=>[
      "threatTypes"     =>["MALWARE", "SOCIAL_ENGINEERING"],
      "platformTypes"   =>["WINDOWS"],
      "threatEntryTypes"=>["URL"],
      "threatEntries"   =>[
        ["url"=>"http://goooogleadsence.biz/"],
        ["url"=>"http://www.urltocheck2.org/"],
        ["url"=>"http://activefile.ucoz.com/"]
      ]
    ]
];
$data_json = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
var_dump($result); // -> string(3) "{}"
curl_close($ch);
0

There are 0 best solutions below