Hi,
I am trying to use the Bing API to retrieve the first image on whatever search query I enter and then strore the url of the image in MySQL. I am nearly there with it but I am getting an error which I am unable to fix.
The above code is run about 400 times through all the movie titles.Code:BingService service = new BingService(); SearchRequest request = new SearchRequest(); request.AppId = "MYAPPID"; request.Query = filePaths[i] + " dvd"; request.Sources = new SourceType[] { SourceType.Image }; SearchResponse response = service.Search(request); OdbcCom = new OdbcCommand("INSERT INTO movies(db_image,db_title,db_quality) values (?,?,?)", OdbcCon); OdbcCom.Parameters.Add("@db_image", OdbcType.Text).Value = response.Image.Results[0].MediaUrl; OdbcCom.Parameters.Add("@db_title", OdbcType.Text).Value = filePaths[i]; OdbcCom.Parameters.Add("@db_quality", OdbcType.Int).Value = 0; OdbcCom.ExecuteNonQuery();
Although I keep getting the error on the bold line above:
I am still quite new to C# but I am thinking that it is running through the movies so quickly that the Bing API is unable to keep up with getting the images? Someone can tell me if I am way off base..Code:Object reference not set to an instance of an object.
Can someone point me in the right direction?
I tested to see if the response was null by doing the following:
It still throws the error. Maybe I am doing it wrong?Code:if (response.Image.Results[0].MediaUrl == null) { Console.Writeline("Null"); } else { OdbcCom.Parameters.Add("@db_image", OdbcType.Text).Value = response.Image.Results[0].MediaUrl; }
Thanks
Jay




Reply With Quote