.NET

2013-02-14 16 views
7

में Google कस्टम खोज API का उपयोग करने के लिए चरण मैं अपने .NET प्रोजेक्ट में Google कस्टम खोज API का उपयोग करने का प्रयास कर रहा हूं। मेरे पास मेरी कंपनी द्वारा प्रदान की गई एक एपीआई कुंजी है। मैंने अपने Google खाते का उपयोग करके कस्टम खोज इंजन बनाया है और 'cx' मान कॉपी किया है।.NET

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}&cx={1}&q={2}&alt=json", apiKey, cx, query)); 

मैं निम्न त्रुटि हो रही है:

मैं निम्नलिखित कोड का उपयोग कर रहा

मैं भी निम्न कोड की कोशिश की है: "। (403) निषिद्ध दूरस्थ सर्वर ने एक त्रुटि दी" :

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); 
} 

यहाँ मैं निम्न अपवाद पर (लायें) मिलती है:

Google.Apis.Requests.RequestError पहुँच कॉन्फ़िगर नहीं किया गया [403] त्रुटियां [संदेश [पहुंच कॉन्फ़िगर नहीं किया गया] स्थान [-] कारण [accessNotConfigured] डोमेन [usageLimits]

CX पैरामीटर की आवश्यकता है? क्या मुझे त्रुटि मिल रही है क्योंकि मैं अपनी कंपनी द्वारा प्रदान की गई कुंजी का उपयोग कर रहा हूं और कस्टम खोज इंजन से अपने Google खाते का उपयोग कर सीएक्स पैरामीटर का उपयोग कर रहा हूं?

क्या 'सीएक्स' पाने का कोई और तरीका है? हम Google एडी प्रदर्शित नहीं करना चाहते हैं।

सहायता के लिए अग्रिम धन्यवाद।

उत्तर

10

मुझे यकीन नहीं है कि आप अभी भी इसमें रुचि रखते हैं या नहीं।

विज्ञापनों के बिना परिणाम प्राप्त करने के लिए आपको इसके लिए भुगतान करना होगा। Info @ Google

और हाँ सीएक्स आवश्यक है क्योंकि यह Google कस्टम सर्च इंजन को निर्दिष्ट करता है जिसे आप खोज के लिए उपयोग करना चाहते हैं। आप यहाँ This google page

से एक कस्टम खोज इंजन बना सकते हैं और कर सकते हैं वर्तमान एपीआई संस्करण 1.3.0 बीटा के लिए खोज परिणाम लाने के वर्तमान कोड है

 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); 
     } 

आशा इस

8

के बजाय मदद करता है ,

var search = listRequest.Fetch(); 

लेकिन अब यह Fetch() विधि का समर्थन नहीं करता है, बल्कि आपको Execute() विधि का उपयोग करने की आवश्यकता है।

var search = listRequest.Execute(); 
+1

देखें http://hintdesk.com/c-how-to-use-google-custom-search-api/ – Cel

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^