Google 安全浏览 API 没有响应 - 发回响应状态
Google Safe browsing API is not responding - sending back response status
我正在尝试将 Google 安全浏览 API 集成到我的网站。 documentation:
我尝试过的:
$apiKey = 'MyFakeAPiKey-pozpkefpoqskpfazejsqpi';
$url = 'http://www.bbc.com/';
$url = urlencode($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://sb-ssl.google.com/safebrowsing/api/lookup?client=firefox&key='. $apiKey.'&appver=1.5.2&pver=4.0&url='.$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Content-length: auto";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo print_r($result, true);
我没有得到response.What我做错了吗?
我找到了解决办法。一切都按预期工作。
$url = 'http://911.sos-empleados.net';
$apiKey = 'Your API';
$apiUrl = 'https://safebrowsing.googleapis.com/v4/threatMatches:find?key='.$apiKey;
$params = [
'client' => [
'clientId' => 'foobar',
'clientVersion' => '1.2.3'
],
'threatInfo' => [
"threatTypes" =>["MALWARE", "SOCIAL_ENGINEERING"],
"platformTypes" => ["WINDOWS"],
'threatEntryTypes' => ['URL'],
'threatEntries' => [
[ 'url' => $url ]
]
]
];
$ch = curl_init($apiUrl);
curl_setopt_array($ch, [
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 1,
CURLOPT_POSTFIELDS => json_encode($params),
CURLOPT_HTTPHEADER => [
'Content-Type: text/json'
]
]);
$res = curl_exec($ch);
?> <pre><?php echo print_r($res, true); ?></pre> <?php
?>
您使用的是旧版本的 API。您代码中的端点对应于安全浏览的第 1 版 API,该版本已于 2011 年 12 月弃用,此后已关闭。
您需要更新到支持的 API 版本 -- 最好是 v4,因为它是最新的。
我正在尝试将 Google 安全浏览 API 集成到我的网站。 documentation:
我尝试过的:
$apiKey = 'MyFakeAPiKey-pozpkefpoqskpfazejsqpi';
$url = 'http://www.bbc.com/';
$url = urlencode($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://sb-ssl.google.com/safebrowsing/api/lookup?client=firefox&key='. $apiKey.'&appver=1.5.2&pver=4.0&url='.$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Content-length: auto";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo print_r($result, true);
我没有得到response.What我做错了吗?
我找到了解决办法。一切都按预期工作。
$url = 'http://911.sos-empleados.net';
$apiKey = 'Your API';
$apiUrl = 'https://safebrowsing.googleapis.com/v4/threatMatches:find?key='.$apiKey;
$params = [
'client' => [
'clientId' => 'foobar',
'clientVersion' => '1.2.3'
],
'threatInfo' => [
"threatTypes" =>["MALWARE", "SOCIAL_ENGINEERING"],
"platformTypes" => ["WINDOWS"],
'threatEntryTypes' => ['URL'],
'threatEntries' => [
[ 'url' => $url ]
]
]
];
$ch = curl_init($apiUrl);
curl_setopt_array($ch, [
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 1,
CURLOPT_POSTFIELDS => json_encode($params),
CURLOPT_HTTPHEADER => [
'Content-Type: text/json'
]
]);
$res = curl_exec($ch);
?> <pre><?php echo print_r($res, true); ?></pre> <?php
?>
您使用的是旧版本的 API。您代码中的端点对应于安全浏览的第 1 版 API,该版本已于 2011 年 12 月弃用,此后已关闭。
您需要更新到支持的 API 版本 -- 最好是 v4,因为它是最新的。