如何通过google-news-api获取数据
How to get data through google-news-api
我想在 C# 中创建一个控制台应用程序以从 google-news-api 获取数据(google 新闻详细信息)。
我被这样试过
static void Main(string[] args)
{
using (var _http = new HttpClient())
{
_http.BaseAddress = new Uri("https://newsapi.org/v2/");
_http.DefaultRequestHeaders.Clear();
_http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await _http.GetAsync("everything?sources=&q=bbc-news&sortBy=publishedAt&pageSize=80&apiKey=4dbc17e007ab436fb66416009dfb59a8");
response.EnsureSuccessStatusCode();
using (HttpContent content = response.Content)
{
}
}
}
参考:-google news api
希望这会有所帮助。
static void Main(string[] args)
{
using (var _http = new HttpClient())
{
_http.BaseAddress = new Uri("https://newsapi.org/v2/");
_http.DefaultRequestHeaders.Clear();
_http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string response = MainAsync(_http).Result;
//TODO: Handel the response string the way you wanted to
}
}
static async Task<string> MainAsync(HttpClient _http)
{
HttpResponseMessage response = await _http.GetAsync("everything?sources=&q=bbc-news&sortBy=publishedAt&pageSize=80&apiKey=4dbc17e007ab436fb66416009dfb59a8");
return await response.Content.ReadAsStringAsync();
}
我想在 C# 中创建一个控制台应用程序以从 google-news-api 获取数据(google 新闻详细信息)。 我被这样试过
static void Main(string[] args)
{
using (var _http = new HttpClient())
{
_http.BaseAddress = new Uri("https://newsapi.org/v2/");
_http.DefaultRequestHeaders.Clear();
_http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await _http.GetAsync("everything?sources=&q=bbc-news&sortBy=publishedAt&pageSize=80&apiKey=4dbc17e007ab436fb66416009dfb59a8");
response.EnsureSuccessStatusCode();
using (HttpContent content = response.Content)
{
}
}
}
参考:-google news api
希望这会有所帮助。
static void Main(string[] args)
{
using (var _http = new HttpClient())
{
_http.BaseAddress = new Uri("https://newsapi.org/v2/");
_http.DefaultRequestHeaders.Clear();
_http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string response = MainAsync(_http).Result;
//TODO: Handel the response string the way you wanted to
}
}
static async Task<string> MainAsync(HttpClient _http)
{
HttpResponseMessage response = await _http.GetAsync("everything?sources=&q=bbc-news&sortBy=publishedAt&pageSize=80&apiKey=4dbc17e007ab436fb66416009dfb59a8");
return await response.Content.ReadAsStringAsync();
}