Hej,

zacząłem uczyć się C# od podstaw, stawiając sobie za cel pierwszą aplikację, która za pomocą Google API wyszuka mi w opisach stron konkretne stringi i zbierze wszystkie ich wariacje w pliku.

Aplikacja będzie bazować na szkielecie, który znalazłem w necie:

GoogleSearch.cs

using System;
using System.Collections.Generic;
using Google.Apis.Customsearch.v1;
using Google.Apis.Customsearch.v1.Data;
using Google.Apis.Services;

namespace TestGoogleSearch
{
    public class GoogleSearch
    {
        //API Key
        private static string API_KEY = "api";

        //The custom search engine identifier
        private static string cx = "cx";

        public static CustomsearchService Service = new CustomsearchService(
            new BaseClientService.Initializer
        {
            ApplicationName = "appname",
            ApiKey = API_KEY,
        });

        public static IList<Result> Search(string query)
        {
            Console.WriteLine("Looking for: {0} ...", query);

            CseResource.ListRequest listRequest = Service.Cse.List(query);
            listRequest.Cx = cx;

            Search search = listRequest.Execute();
            return search.Items;
        }
    }
}

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Apis.Customsearch.v1.Data;

namespace TestGoogleSearch
{
class Program
{
    static void Main(string[] args)
    {
        string query = "\"szukany string1\" + \"szukany string2\"";
        var results = GoogleSearch.Search(query);
        foreach (Result result in results)
        {
            Console.WriteLine("-----------------------------------");
            Console.WriteLine("Title: {0}", result.Title);
            Console.WriteLine("Link: {0}", result.Link);
            Console.WriteLine("Snippet: {0}", result.Snippet);
        }
        Console.ReadKey();
    }
}
}

Moje pytania:

  1. Jak i gdzie, powinienem dodać interesujące mnie parametry CSE (np. od którego wyniku zacząć wyszukiwanie, lub ile jest wyników in total).
    https://developers.google.com/custom-search/json-api/v1/reference/cse/list
  2. Czy mogę to zrobić bez modyfikacji referencji odpowiadającej za API?

Z góry dzięki za pomoc!