如何使用适用于 .NET 的 Google 自定义搜索 API 进行搜索?
问题描述:
我刚刚发现了 适用于 .NET 的 Google API 客户端库,但由于缺乏文档,我很难弄清楚.
I just discovered the Google APIs Client Library for .NET, but because of lack of documentation I have a hard time to figure it out.
我正在尝试通过进行自定义搜索来进行简单的测试,并且查看了以下命名空间:
I am trying to do a simple test, by doing a custom search, and I have looked among other, at the following namespace:
Google.Apis.Customsearch.v1.Data.Query
我已尝试创建查询对象并填写 SearchTerms,但如何从该查询中获取结果?
I have tried to create a query object and fill out SearchTerms, but how can I fetch results from that query?
答
看API参考使用来自 google-api-dotnet-client
CustomsearchService svc = new CustomsearchService();
string json = File.ReadAllText("jsonfile",Encoding.UTF8);
Search googleRes = null;
ISerializer des = new NewtonsoftJsonSerializer();
googleRes = des.Deserialize<Search>(json);
或
CustomsearchService svc = new CustomsearchService();
Search googleRes = null;
ISerializer des = new NewtonsoftJsonSerializer();
using (var fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
googleRes = des.Deserialize<Search>(fileStream);
}
通过流,您还可以根据需要读取 webClient
或 HttpRequest
with the stream you can also read off of webClient
or HttpRequest
, as you wish