Reputation: 2768
I have been working on google safe browsing API - I am sure I am doing everything correct but I get the error when I try to connect to the API
"Object reference not set to an instance of an object."
I have correct nuGet package installed
My code is the following
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();
}
I think i am messing up at var response = googleClient.DownloadString
but I am not sure what is the correct call method for this.
Does anyone have any idea?
Cheers
Upvotes: 0
Views: 236
Reputation: 310
I used ThreatMatches.Find()
and it worked.
ThreatMatchesResource.FindRequest request = service.ThreatMatches.Find(
new FindThreatMatchesRequest{Client = client, ThreatInfo = threatInfo});
FindThreatMatchesResponse execute = await request.ExecuteAsync();
var releases = execute.ToString();
Upvotes: 1
Reputation: 443
You need to put your api key in
googleClient.DownloadString("https://safebrowsing.googleapis.com/v4/" + client + threadInfo + "&key=myapikey");
Upvotes: 0