谷歌安全浏览 V4 - 无法发送请求



我一直在研究谷歌安全浏览API - 我确定我做的一切都是正确的,但是当我尝试连接到API时出现错误

"对象引用未设置为对象的实例。">

我安装了正确的 nuGet 包

我的代码如下

try
{
    //cient_info
    Google.Apis.Safebrowsing.v4.Data.ClientInfo client = new Google.Apis.Safebrowsing.v4.Data.ClientInfo();
    client.ClientId = "testapp";
    client.ClientVersion = "1";
    //thread_info
    Google.Apis.Safebrowsing.v4.Data.ThreatInfo threadInfo = new Google.Apis.Safebrowsing.v4.Data.ThreatInfo();
    threadInfo.ThreatTypes.Add("MALWARE");
    threadInfo.ThreatTypes.Add("SOCIAL_ENGINEERING");
    threadInfo.PlatformTypes.Add("WINDOWS");
    threadInfo.ThreatEntryTypes.Add("URL");
    //url to check
    Google.Apis.Safebrowsing.v4.Data.ThreatEntry ITEM = new Google.Apis.Safebrowsing.v4.Data.ThreatEntry();
    ITEM.Url = "http://www.google.com.au/";
    threadInfo.ThreatEntries.Add(ITEM);
    //API Call
    var googleClient = new WebClient();
    var response = googleClient.DownloadString("https://safebrowsing.googleapis.com/v4/" + client + threadInfo + "&key=myapikey");
    var releases = JObject.Parse(response);
    return releases.ToString();
}
catch (Exception X)
{
    var Error = X.Message;
    return Error.ToString();
}

我想我在var response = googleClient.DownloadString搞砸了,但我不确定正确的调用方法是什么。

有人知道吗?

干杯

我用了ThreatMatches.Find(),它奏效了。

ThreatMatchesResource.FindRequest request = service.ThreatMatches.Find(
new FindThreatMatchesRequest{Client = client, ThreatInfo = threatInfo});
FindThreatMatchesResponse execute = await request.ExecuteAsync();
var releases = execute.ToString();
你需要

把你的 api 密钥放进去

googleClient.DownloadString("https://safebrowsing.googleapis.com/v4/" + client + threadInfo + "&key=myapikey");

最新更新