Note that there are some explanatory texts on larger screens.

plurals
  1. POSteps for using Google custom search API in .NET
    primarykey
    data
    text
    <p>I am trying to use Google custom search API in my .NET project. I have an API Key provided by my company. I have created a custom search engine using my Google account and copied the 'cx' value.</p> <p>I am using the following code:</p> <pre><code>string apiKey = "My company Key"; string cx = "Cx"; string query = tbSearch.Text; WebClient webClient = new WebClient(); webClient.Headers.Add("user-agent", "Only a test!"); string result = webClient.DownloadString(String.Format("https://www.googleapis.com/customsearch/v1?key={0}&amp;cx={1}&amp;q={2}&amp;alt=json", apiKey, cx, query)); </code></pre> <p>I am getting the following error: "The remote server returned an error: (403) Forbidden. "</p> <p>I have tried the following code too:</p> <pre><code>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); } </code></pre> <p>Here I get the following exception at Fetch():</p> <p>Google.Apis.Requests.RequestError Access Not Configured [403] Errors [Message[Access Not Configured] Location[ - ] Reason[accessNotConfigured] Domain[usageLimits]</p> <p>Is CX parameter required? Am I getting the error because I am using the Key provided by my company and using the CX parameter from custom search engine using my Google account?</p> <p>Is there any other way of getting 'cx'? We don't want to display Google ADs.</p> <p>Thank you very much in advance for help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload