Steps for using Google custom search API in .NET

南笙酒味 提交于 2019-11-30 14:03:17

Instead of,

var search = listRequest.Fetch();

But now it does not supports Fetch() method, rather you need to use Execute() method.

var search = listRequest.Execute();

I'm not sure if you are still interested in this.

To get results without ads you need to pay for it. Info @ Google

and yes the cx is required because it specifies the google custom search engine that you want to use to search. you can create a custom search engine from This google page

and here is the current code to retrieve search results for the current api version 1.3.0-beta

        string apiKey = "Your api key";
        string cx = "Your custom search engine id";
        string query = "Your query";

        var svc = new Google.Apis.Customsearch.v1.CustomsearchService(new BaseClientService.Initializer { ApiKey = apiKey });
        var listRequest = svc.Cse.List(query);

        listRequest.Cx = cx;
        var search = listRequest.Fetch();

        foreach (var result in search.Items)
        {
            Response.Output.WriteLine("Title: {0}", result.Title);
            Response.Output.WriteLine("Link: {0}", result.Link);
        }

Hope this helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!