gpt4 book ai didi

java - Google 安全浏览 v4 API java

转载 作者:行者123 更新时间:2023-11-30 06:28:34 25 4
gpt4 key购买 nike

这是查看哪个网址可以安全浏览的代码。我已经使用了 google api。我面临的问题是我无法获取 SafeBrowsing 类对象来访问给定的 url。所以请看看是否有人有解决方案。

 public static void main(final String[] args) {
try {
final String baseURL = "https://safebrowsing.googleapis.com/v4/threatMatches:find?key=xxx";
final URL url = new URL(baseURL);

// Get a URLConnection object, to write to POST method
final HttpURLConnection connect = (HttpURLConnection) url.openConnection();
connect.setRequestMethod("POST");
connect.setRequestProperty("Content-Type", "application/json");
// Specify connection settings
connect.setDoInput(true);
connect.setDoOutput(true);
final ClientInfo clientInfo = new Ggooggle().getClientInfo();
final ThreatInfo threatInfo = new Ggooggle().getThreatInfo();
final FindThreatMatchesRequest request = new FindThreatMatchesRequest();
request.setClient(clientInfo);
request.setThreatInfo(threatInfo);

最佳答案

试试这个。

public final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
public static final JacksonFactory GOOGLE_JSON_FACTORY = JacksonFactory.getDefaultInstance();

Safebrowsing.Builder safebrowsingBuilder = new Safebrowsing.Builder(httpTransport, GOOGLE_JSON_FACTORY, null);
Safebrowsing safebrowsing = safebrowsingBuilder.build();
FindThreatMatchesResponse findThreatMatchesResponse = safebrowsing.threatMatches().find(findThreatMatchesRequest).setKey(GOOGLE_API_KEY).execute();

List<ThreatMatch> threatMatches = findThreatMatchesResponse.getMatches();

if (threatMatches != null && threatMatches.size() > 0) {
for (ThreatMatch threatMatch : threatMatches) {
threatUrls.add(threatMatch.getThreat().getUrl());
}
}

完整示例代码:https://github.com/kalinchih/java_google_safebrowsing_v4

关于java - Google 安全浏览 v4 API java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46599053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com