Tuesday, 15 January 2013

c# - Steps for using Google custom search API in .NET -



c# - Steps for using Google custom search API in .NET -

i trying utilize google custom search api in .net project. have api key provided company. have created custom search engine using google business relationship , copied 'cx' value.

i using next code:

string apikey = "my company key"; string cx = "cx"; string query = tbsearch.text; webclient webclient = new webclient(); webclient.headers.add("user-agent", "only test!"); string result = webclient.downloadstring(string.format("https://www.googleapis.com/customsearch/v1?key={0}&cx={1}&q={2}&alt=json", apikey, cx, query));

i getting next error: "the remote server returned error: (403) forbidden. "

i have tried next code too:

google.apis.customsearch.v1.customsearchservice svc = new google.apis.customsearch.v1.customsearchservice(); svc.key = apikey; google.apis.customsearch.v1.cseresource.listrequest listrequest = svc.cse.list(query); listrequest.cx = cx; google.apis.customsearch.v1.data.search search = listrequest.fetch(); foreach (google.apis.customsearch.v1.data.result result1 in search.items) { console.writeline("title: {0}", result1.title); console.writeline("link: {0}", result1.link); }

here next exception @ fetch():

google.apis.requests.requesterror access not configured [403] errors [message[access not configured] location[ - ] reason[accessnotconfigured] domain[usagelimits]

is cx parameter required? getting error because using key provided company , using cx parameter custom search engine using google account?

is there other way of getting 'cx'? don't want display google ads.

thank much in advance help.

i'm not sure if still interested in this.

to results without ads need pay it. info @ google

and yest cx required because specifies google custom search engine want utilize search. can create custom search engine this google page

and here current code retrieve search results 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 helps

c# .net google-custom-search

No comments:

Post a Comment