【发布时间】:2015-06-20 16:13:51
【问题描述】:
我使用 Google 自定义搜索 API 已有几年了。此代码适用于 Google nuget 包“Google.Apis.Customsearch.v1 客户端库”(v1.9.0.460)。
这是我的 C# 代码:
public Search SearchNow(string query)
{
CustomsearchService service = new CustomsearchService(
new BaseClientService.Initializer()
{
ApiKey = Properties.Resources.Google_Key,
ApplicationName = "my-app-name"
});
CseResource.ListRequest req = service.Cse.List(query);
req.Cx = Properties.Resources.Google_CX;
req.Start = 1;
return req.Execute();
}
这段代码在我的服务器上运行了一年多,没有任何问题。从上周开始,我开始恢复这个异常:
服务 customsearch 抛出了异常: Google.GoogleApiException:Google.Apis.Requests.RequestError 无效
值 [400] 错误
[消息[无效值]位置[-]原因[无效]域[全局]]
在 Google.Apis.Requests.ClientServiceRequest`1.Execute() 中 c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis\Apis\Requests\ClientServiceRequest.cs:line 96 在 ###.SearchNow(String query, Int64 startResult) in ###.cs:line ***\Tests\Program.cs:line 67 中的 Tests.Program.Main() 中的 144
我不知道发生了什么变化\为什么它停止工作。
我做了一个小测试 - 向谷歌发送“Hello world”搜索查询 - 这是第一次工作。我正在运行这个测试 agian 和 agian,发现这段代码在 70% 的时间里运行良好,其他时候它失败了(上面提到了错误)。
我对这些参数进行了双重验证:ApiKey、ApplicationName、CX。
那么,可能是什么问题?
【问题讨论】:
-
嗨 - 你有想过这个吗?它刚刚开始发生在我身上!
标签: c# google-api google-custom-search