Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在.NET中使用Google安全浏览(v4)_C#_.net_Api_Google Api_Safe Browsing - Fatal编程技术网

C# 如何在.NET中使用Google安全浏览(v4)

C# 如何在.NET中使用Google安全浏览(v4),c#,.net,api,google-api,safe-browsing,C#,.net,Api,Google Api,Safe Browsing,我试图将谷歌安全浏览查找API(v4,)与.NET应用程序一起使用,但很难找到示例代码 我安装了谷歌的nuget软件包,但在他们的github repo上找不到任何例子 我能找到的最好的例子是at,但即使这样也不能确切说明我在寻找什么。我只想查找URL的状态。下面是我从谷歌找到的唯一一个例子 // Create the service. var service = new DiscoveryService(new BaseClientService.Initial

我试图将谷歌安全浏览查找API(v4,)与.NET应用程序一起使用,但很难找到示例代码

我安装了谷歌的nuget软件包,但在他们的github repo上找不到任何例子

我能找到的最好的例子是at,但即使这样也不能确切说明我在寻找什么。我只想查找URL的状态。下面是我从谷歌找到的唯一一个例子

        // Create the service.
        var service = new DiscoveryService(new BaseClientService.Initializer
            {
                ApplicationName = "Discovery Sample",
                ApiKey="[YOUR_API_KEY_HERE]",
            });

        // Run the request.
        Console.WriteLine("Executing a list request...");
        var result = await service.Apis.List().ExecuteAsync();

        // Display the results.
        if (result.Items != null)
        {
            foreach (DirectoryList.ItemsData api in result.Items)
            {
                Console.WriteLine(api.Id + " - " + api.Title);
            }
        }
我还尝试了一个使用

 var client = new LookupClient("key", "dotnet-client");
 var response = await client.LookupAsync("http://amazon.com");
但每次都是“未知”的。我确保我在谷歌注册了一个新的密钥,并允许它访问谷歌安全浏览Api 4

关于如何使用谷歌api只获取一个或多个URL的响应,有什么建议吗


谢谢你

经过反复试验,我终于找到了答案

我的原始代码试图使用
LookupClient
,但这对我不起作用。我通过查看google如何初始化他们的发现服务找到了解决方案,并从中构建了
FindthreatMatchesRequest()

var service=new SafebrowsingService(new BaseClientService.Initializer
{
ApplicationName=“dotnet客户端”,
ApiKey=“API-KEY”
});
var request=service.ThreatMatches.Find(新的FindThreatMatchesRequest()
{
Client=newclientinfo
{
ClientId=“Dotnet客户端”,
ClientVersion=“1.5.2”
},
ThreatInfo=新ThreatInfo()
{
ThreatTypes=新列表{“恶意软件”},
PlatformTypes=新列表{“Windows”},
ThreatEntryTypes=新列表{“URL”},
ThreatEntries=新列表
{
新威胁论
{
Url=“google.com”
}
}
}
});
var response=wait request.ExecuteAsync();

希望这能帮助任何寻求快速解决方案的人。别忘了添加你的Api密钥

我通过寻找将我的应用程序与Google SafeBrowsing集成的解决方案找到了这条线索。这对我来说很有效,但我想补充一点,我也添加了这一行

return (FindThreatMatchesResponse)response;
在上面发布的代码末尾,将其包装在一个名为

protected async Task<FindThreatMatchesResponse> GoogleCheckAsync()
如果要检查更多可疑站点,可能还需要将代码的相关部分替换为以下内容:

ThreatTypes=新列表{“恶意软件”、“社会工程”、“不需要的软件”、“潜在有害的应用程序”},
PlatformTypes=新列表{“任何平台”},
protected async Task<FindThreatMatchesResponse> GoogleCheckAsync()