public List <SOPage> GoogleStackoverflowSearch(string query) { const string apiKey = "AIzaSyA04T2CMJSaGS9AWl66v43rzZTi7z4iKJw"; const string searchEngineId = "015600743573451307836:fzhqm3defkg"; CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(query); listRequest.Cx = searchEngineId; Search search = listRequest.Execute(); List <SOPage> results = new List <SOPage>(); if (search?.Items?.Count > 0) { foreach (var item in search.Items) { results.Add(new SOPage { Title = item.Title, URL = item.Link }); } } return(results); }
public Search getFirstMovie(string movieTitle) { try { keys(); query = movieTitle; CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(query); listRequest.Cx = searchEngineId; Search search = listRequest.Execute(); foreach (var item in search.Items) { Console.WriteLine("Title : " + item.Title + Environment.NewLine + "Link : " + item.Link + Environment.NewLine + Environment.NewLine); } Console.ReadLine(); return(search); } catch (Exception er) { Console.WriteLine("Error message: " + er.ToString()); throw; } }
public ArrayList search(string query) { objArray = new ArrayList(); Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(query); listRequest.Cx = searchEngineId; listRequest.SearchType = Google.Apis.Customsearch.v1.CseResource.ListRequest.SearchTypeEnum.Image; for (int i = 0; i < 1; i++) { listRequest.Start = (i * 10) + 1; Search search = listRequest.Execute(); foreach (var item in search.Items) { Image tempimg = new Image(); tempimg.title = item.Title; tempimg.link = item.Link; objArray.Add(tempimg); } } return(objArray); }
private void Search(CustomsearchService searchservice, string term, int n_searches, /*out*/ List <Double_Links> imageUrls) { ListRequest listRequest = searchservice.Cse.List(); // listRequest.CreateRequest(); listRequest.Cx = "ca0ca9bbd59600922"; listRequest.SearchType = ListRequest.SearchTypeEnum.Image; listRequest.ImgColorType = ListRequest.ImgColorTypeEnum.ImgColorTypeUndefined; if (term == "") { return; } listRequest.Q = term; listRequest.Num = n_searches; var search = listRequest.Execute(); if (search.Items == null) { return; } foreach (Result result in search.Items) { imageUrls.Add(new Double_Links { thumbnail = result.Image.ThumbnailLink, picture = result.Link }); } }
/// <summary> /// This returns a URL for an image. /// This uses Google and will return the first image result from a search term. /// </summary> /// <param name="searchTerms"></param> /// <returns></returns> public static string DownloadImage(string searchTerms) { // This is my private API key string apiKey = "AIzaSyAD5OsjTu6d-8xwOEkewvgA0JtNecMfoNo"; // Google Images Engine ID string searchEngineId = "008801159646905401147:nqod7kqw_kc"; // C# Library provided by Google to handle search commands CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer { ApiKey = apiKey }); // Request a list of search results Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(searchTerms); // Assign vars for the search listRequest.Cx = searchEngineId; listRequest.SearchType = CseResource.ListRequest.SearchTypeEnum.Image; listRequest.Num = 1; listRequest.Start = 1; // Execute the search Search search = listRequest.Execute(); // Validate quantity of search results if (search.Items.Count == 0) { return(string.Empty); } // Return the very first image found (URL to) return(search.Items[0].Link); }
private static void Main(string[] args) { //// Search 32 results of keyword : "Google APIs for .NET" //GwebSearchClient client = new GwebSearchClient(/* Enter the URL of your site here */); //IList<IWebResult> results = client.Search("Google API for .NET", 32); //foreach (IWebResult result in results) //{ // Console.WriteLine("[{0}] {1} => {2}", result.Title, result.Content, result.Url); //} //WebQuery query = new WebQuery("Insert query here"); //query.StartIndex.Value = 2; //query.HostLangauge.Value = Languages.English; //IGoogleResultSet<GoogleWebResult> resultSet = GoogleService.Instance.Search<GoogleWebResult>(query); //const string apiKey = "YOUR_API_KEY"; //const string searchEngineId = "010297209645085268115:tvi4k-bftis"; //const string query = "'sky is blue'"; //CustomsearchService customSearchService = // new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); //Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(query); //listRequest.Cx = searchEngineId; //Search search = listRequest.Execute(); //foreach (var item in search.Items) //{ // Console.WriteLine("Title : " + item.Title + Environment.NewLine + "Link : " + item.Link + // Environment.NewLine + "Description: " + item.Snippet + Environment.NewLine); //} //Console.ReadLine(); const string apiKey = "YOUR_API_KEY"; const string searchEngineId = "003470263288780838160:ty47piyybua"; const string query = "sky is blue"; CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(query); listRequest.Cx = searchEngineId; Search search = listRequest.Execute(); foreach (var item in search.Items) { Console.WriteLine("Title : " + item.Title + Environment.NewLine + "Link : " + item.Link + Environment.NewLine + item.Snippet + Environment.NewLine); } Console.ReadLine(); }
private void button1_Click_1(object sender, System.EventArgs e) { try { richTextBox1.Text = ""; const string apiKey = "AIzaSyDIm9ZOWD8Zd-2tHy5r3c0R-_XjdEFaXGE"; const string searchEngineId = "003470263288780838160:ty47piyybua"; string query1 = textBox1.Text; CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(query1); listRequest.Cx = searchEngineId; Search search = listRequest.Execute(); foreach (var item in search.Items) { richTextBox1.Text += item.Link; richTextBox1.Text += " \n "; } richTextBox1.Text += " \n ---------------------- \n "; Repeater rptResult = new Repeater(); string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; string query = textBox1.Text; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); string market = "en-us"; bingContainer.Credentials = new NetworkCredential("bucsexiyu8a87Nw1u3mmTJ/BCPAzGOKFQcydlXYn1S8", "bucsexiyu8a87Nw1u3mmTJ/BCPAzGOKFQcydlXYn1S8"); var webQuery = bingContainer.Web(query, null, null, null, null, null, null, null); webQuery = webQuery.AddQueryOption("$top", 10); var webResults = webQuery.Execute(); System.Windows.Forms.Label lblResults = new System.Windows.Forms.Label(); StringBuilder searchResult = new StringBuilder(); foreach (Bing.WebResult wResult in webResults) { richTextBox1.Text += wResult.Url; } }catch (Exception ex) { richTextBox1.Text = "404 Not Found"; } }
private void _GooglePlusSearch() { const string searchEngineId = "011018437923151163157:zuxxfb2fjrc"; CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(Query); listRequest.Cx = searchEngineId; listRequest.Num = 10; Search search = listRequest.Execute(); _googlePlusSearch = search; }
private void Form2_Load(object sender, EventArgs e) { // holding positions for form 2 List <String> imageList = new List <string>(); CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(); // .Q is the search query. Word we are searching for listRequest.Q = wordSearch; // how many requests we are making. default 10 listRequest.Num = 9; // search id listRequest.Cx = searchKey; // searching for image type only listRequest.SearchType = CseResource.ListRequest.SearchTypeEnum.Image; // var search having the specifications we gave to listRequest so we know what we are looking for var search = listRequest.Execute(); ImageList img = new ImageList(); img.ImageSize = new Size(150, 150); img.ColorDepth = ColorDepth.Depth32Bit; var i = 0; foreach (var result in search.Items) { // making it able to the user to see the images imageList.Add(result.Link); imgList = imageList; WebClient w = new WebClient(); byte[] imageByte = w.DownloadData(imageList[i]); MemoryStream stream = new MemoryStream(imageByte); Image im = Image.FromStream(stream); img.Images.Add(im); image = img; imgView.Items.Add("", i); i++; } imgView.LargeImageList = img; }
private void searchButton_Click(object sender, EventArgs e) { imageArr.Clear(); imageArrIndex = 0; imageArrSize = 0; if (!searchText.Equals("")) { var svc = new Google.Apis.Customsearch.v1.CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer { ApiKey = key }); Console.WriteLine(searchText); //var listRequest = svc.Cse.List(searchText); Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = svc.Cse.List(searchText); listRequest.Cx = searchID; listRequest.SearchType = Google.Apis.Customsearch.v1.CseResource.ListRequest.SearchTypeEnum.Image; for (int i = 0; i < 5; i++) { listRequest.Start = 1 + 10 * i; Google.Apis.Customsearch.v1.Data.Search search = listRequest.Execute(); foreach (var result in search.Items) { imageArrIndex++; imageArr.Add((Image)BitmapFromURL(result.Image.ThumbnailLink)); //if (!result.Pagemap.Equals(null) && result.Pagemap.ContainsKey("cse_thumbnail")) //{ // //Console.WriteLine(result.Pagemap["cse_thumbnail"][0]["src"]); // imageArrIndex++; // imageArr.Add((Image)BitmapFromURL(result.Pagemap["cse_thumbnail"][0]["src"].ToString())); //} //imageArr[imageArrIndex++] = result.Image.; //pictureBox1.Image = result.Image.ThumbnailLink; } } imageArrSize = imageArrIndex; imageArrIndex = 0; pictureBox1.Image = imageArr[imageArrIndex]; } }
static void Main(string[] args) { /* apikey with searchEngineID is setup when create google custom key * U can create more than one searchEngineId */ const string apiKey = "AIzaSyCUqfT2QmAZA4668MPLGzLR0TxGOmqAvoM"; string[] searchEngine = { "014643630663003986242:kxn6ai0cdom", "014643630663003986242:7vybp9qqc4y", "014643630663003986242:bbkgkcu0nzw", "014643630663003986242:2xzxd8s8pbu", "014643630663003986242:n9qaxhzeukq", "014643630663003986242:fbdjtqdrwsy", "014643630663003986242:apoeesjvmq4", "014643630663003986242:ry__xhewmma", "014643630663003986242:hqmstvd27xi", "014643630663003986242:xyjlkndt-68", "014643630663003986242:pga9pplj_5w", "014643630663003986242:bbx5ubgnoti", "014643630663003986242:traumvifdgc", "014643630663003986242:ld_-gigmcbu", "014643630663003986242:edd7oeqtf50", "014643630663003986242:p8hvgjehmt4", "014643630663003986242:aegk6ogs0em", "014643630663003986242:a0skashuy6w", "014643630663003986242:iqbhww3mgly", "014643630663003986242:maelom8dwwm", "014643630663003986242:zvrnazoxz-w", "014643630663003986242:oy1nlwhwaac" }; const string query = "developer"; string searchEngineId; string body = ""; int counter = 1; for (var i = 0; i < searchEngine.Count(); i++) { searchEngineId = searchEngine[i]; CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(query); listRequest.Cx = searchEngineId; // listRequest.ExactTerms = query; Search search = listRequest.Execute(); foreach (var item in search.Items) { //prepare the body for email sent body = body + counter + " Title : " + item.Title + Environment.NewLine + "Link : " + item.Link + Environment.NewLine + Environment.NewLine; //sent the output to console screen // Console.WriteLine(counter +" Title : " + item.Title + Environment.NewLine + "Link : " + item.Link + Environment.NewLine + Environment.NewLine); counter++; } // Console.ReadLine(); } //end of for loop /* * The results above and be used to result to send a Email */ counter = counter - 1; var fromAddress = new MailAddress("*****@*****.**", "SystemSearch"); var toAddress = new MailAddress("*****@*****.**", "Developer search"); const string fromPassword = "******"; string subject = counter.ToString() + " Developer Search Results"; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } }
public void CreateComamnds() { var cService = _client.GetService <CommandService>(); cService.CreateCommand("game") .Description("Owner Only - Sets game") .Parameter("game", ParameterType.Required) .Do(async(e) => { if (e.User.Id == 131182268021604352) { if (e.GetArg("game") != null) { var newgame = e.GetArg("game"); _client.SetGame(newgame); await e.Channel.SendMessage("Game set to: " + newgame); } else { await e.Channel.SendMessage("error"); } } }); cService.CreateCommand("search") .Description("google search!") .Parameter("google", ParameterType.Required) .Do(async(e) => { if (e.GetArg("google") != null) { query = e.GetArg("google"); CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(query); listRequest.Cx = searchEngineId; Search search = listRequest.Execute(); int i = 0; await e.Channel.SendMessage("Sending first 3 items!"); foreach (var item in search.Items) { if (++i == 3) { break; } await e.Channel.SendMessage("Title : " + item.Title + Environment.NewLine + "Link : " + item.Link + Environment.NewLine + Environment.NewLine); } //await e.Channel.SendMessage("Game set to: " + newgame); } else { await e.Channel.SendMessage("error"); } }); cService.CreateCommand("hello") .Description("Says hello") .Parameter("user", ParameterType.Required) .Do(async(e) => { if (e.GetArg("user") != null) { //LOGIC HERE await e.Channel.SendMessage("Hello " + e.User.Name); } else { await e.Channel.SendMessage("Error"); } }); cService.CreateCommand("invite") .Description("Lol its an invite") .Do(async(e) => { await e.Channel.SendMessage("Add our bot to your server: https://discordapp.com/oauth2/authorize?client_id=239794307492610049&scope=bot&permissions=0"); }); cService.CreateCommand("dnd") .Description("Do not disturb") .Do(async(e) => { _client.SetStatus(Discord.UserStatus.DoNotDisturb); await e.Channel.SendMessage("Changed to do not disturb."); }); cService.CreateCommand("online") .Description("online") .Do(async(e) => { _client.SetStatus(Discord.UserStatus.Online); await e.Channel.SendMessage("Changed to online."); }); cService.CreateCommand("idle") .Description("idle") .Do(async(e) => { _client.SetStatus(Discord.UserStatus.Idle); await e.Channel.SendMessage("Changed to idle."); }); //cService.CreateCommand("sendfile") // .Description("sends a file to a channel") // .Do(async (e) => // { // await e.Channel.SendFile("tails.jpg"); // await e.Channel.SendMessage("file sent!"); // }); }