.netjsongoogle-apic#-3.0safe-browsing-api

Google Safe Browsing API v4 implementation with C# returns null response


I am trying to lookup/scan the status of URLs with the Google Safe Browsing API v4, I tried the method I found in this link How to use Google Safe Browsing (v4) with .NET, but i get a null response returned.

Here's the code:

private async void checkUrlBtn_Click(object sender, EventArgs e)
{
    var service = new SafebrowsingService(new BaseClientService.Initializer
    {
        ApplicationName = "dotnet-client",
        ApiKey = "MY_API"
    });

    var request = service.ThreatMatches.Find(new FindThreatMatchesRequest()
    {
        Client = new ClientInfo
        {
            ClientId = "Dotnet-client",
            ClientVersion = "1.5.2"
        },
        ThreatInfo = new ThreatInfo()
        {
            ThreatTypes = new List<string> { "SOCIAL_ENGINEERING" },
            PlatformTypes = new List<string> { "PLATFORM_TYPE_UNSPECIFIED" },
            ThreatEntryTypes = new List<string> { "URL" },
            ThreatEntries = new List<ThreatEntry>
            {
                new ThreatEntry
                {
                    Url = "https://someurlIGotFromPhishtank.com"
                }
            }
        }
    });
    var response = await request.ExecuteAsync();
    string json = JsonConvert.SerializeObject(response);
    string jsonFormatted = JToken.Parse(json).ToString(Formatting.Indented);
    Console.WriteLine(jsonFormatted);
}   

My Response:

{
  "matches": null,
  "ETag": null
}

At this point I feel I am doing something very wrong and I need HELP!!!


Solution

  • First, I feel the need to point out that you just published your private Google API key on a public forum. You need to immediately go and revoke this API Key as soon as you read this response.

    Secondly, you should know that just because you got a URL from a source that has indicated it is a malicious URL, does not mean that Google Safe Browsing will in fact return a response that is is malicious. So the null response you have there could simply be an indication that Google Safe Browsing indeed has no matches for that URL.

    Lastly, if I remember correctly (but I would need to double check to be certain) you can't specify PLATFORM_TYPE_UNSPECIFIED for Platform Types when you make a request. You need to specify one or more specific Platform Types in the request. Maybe try that?