2017-05-30 76 views
0

我需要一点帮助。下面的代码工作flawlesly当我搜索的是网页,但是当我想要搜索的图像使用Google CustomsearchService在网络上搜索图像

 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结果荷兰国际集团nullSearchTypeImage

回答

0

我不好对不起。我忘了在Google CSE页面上打开图片搜索。现在它工作正常。