0

我一直在研究谷歌安全浏览 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但我不确定正确的调用方法是什么。

有人有什么主意吗?

干杯

4

2 回答 2

1

我用过ThreatMatches.Find(),效果很好。

ThreatMatchesResource.FindRequest request = service.ThreatMatches.Find(
new FindThreatMatchesRequest{Client = client, ThreatInfo = threatInfo});

FindThreatMatchesResponse execute = await request.ExecuteAsync();

var releases = execute.ToString();
于 2019-07-04T13:33:04.877 回答
0

您需要将您的 api 密钥放入

googleClient.DownloadString("https://safebrowsing.googleapis.com/v4/" + client + threadInfo + "&key=myapikey");
于 2018-02-09T21:39:14.747 回答