我需要一点帮助。当我按原样搜索网页时,下面的代码会发生故障,但是当我想搜索图像时
const string apiKey = "xxxx";
const string searchEngineId = "xxxx";
const string query = "apple";
var customSearchService = new CustomsearchService(new BaseClientService.Initializer { ApiKey = apiKey });
var listRequest = customSearchService.Cse.List(query);
listRequest.Cx = searchEngineId;
listRequest.Num = 1;
//listRequest.Fields = "items(image(contextLink,thumbnailLink),link)";
listRequest.SearchType = CseResource.ListRequest.SearchTypeEnum.Image;
listRequest.Start = 1;
var search = listRequest.Execute();
foreach (var result in search.Items)
{
Debug.WriteLine(string.Format("Title: {0}", result.Title));
Debug.WriteLine(string.Format("Link: {0}", result.Link));
}
当search.Items
为null
时, SearchType
会产生Image
。
答案 0 :(得分:0)
我很抱歉。我忘记在Google CSE页面上打开图像serch。现在它工作正常。