C# .Net与网站管理员工具(Google.api.Webmasters.v3 Nuget包)的斗争
我想知道是否有人比我更进一步通过.Net使用谷歌网站管理员工具API的新搜索分析功能 我正在使用Google.api.Webmasters.v3 Nuget软件包,并且已经完成了身份验证和连接(使用服务帐户) 然而,我正努力通过搜索分析取得进展 我在网上找不到任何代码示例,所以我在上的类信息和大量猜测的指导下 以下是我正在使用的代码:C# .Net与网站管理员工具(Google.api.Webmasters.v3 Nuget包)的斗争,c#,.net,google-api,google-api-dotnet-client,google-api-webmasters,C#,.net,Google Api,Google Api Dotnet Client,Google Api Webmasters,我想知道是否有人比我更进一步通过.Net使用谷歌网站管理员工具API的新搜索分析功能 我正在使用Google.api.Webmasters.v3 Nuget软件包,并且已经完成了身份验证和连接(使用服务帐户) 然而,我正努力通过搜索分析取得进展 我在网上找不到任何代码示例,所以我在上的类信息和大量猜测的指导下 以下是我正在使用的代码: SearchanalyticsResource mySearchanalyticsResource = new SearchanalyticsResource(s
SearchanalyticsResource mySearchanalyticsResource = new SearchanalyticsResource(service);
SearchAnalyticsQueryRequest myRequest = new SearchAnalyticsQueryRequest();
myRequest.StartDate = "2015-08-01";
myRequest.EndDate = "2015-08-31";
myRequest.RowLimit = 10;
SearchanalyticsResource.QueryRequest myQueryRequest = mySearchanalyticsResource.Query(myRequest, site.SiteUrl);
SearchAnalyticsQueryResponse myQueryResponse = myQueryRequest.Execute();
它运行OK,直到我得到“发生错误,但错误响应无法反序列化”时的Execute方法。异常详细信息如下
Newtonsoft.Json.JsonReaderException{“分析NaN值.路径“”时出错,第0行,位置0.”
我们将非常感谢您的帮助或代码示例 这会编译,但不会为我返回任何数据 Auth:
public static WebmastersService WMAuthenticateOauth(string clientId, string clientSecret, string userName)
{
string[] scopes = new string[] { WebmastersService.Scope.Webmasters }; // View analytics data
try
{
// here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
, scopes
, userName
, CancellationToken.None
, new FileDataStore(".", true)).Result;
WebmastersService service = new WebmastersService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "WebMasters API Sample",
});
return service;
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
return null;
}
}
请求
var service = Authentcation.WMAuthenticateOauth(clientid, secret, "testmmm");
IList<string> newlist = new List<string> ();
newlist.Add("country");
newlist.Add("device");
SearchAnalyticsQueryRequest body = new SearchAnalyticsQueryRequest();
body.StartDate = "2015-04-01";
body.EndDate = "2015-05-01";
body.Dimensions = newlist;
var result = service.Searchanalytics.Query(body, "http://www.daimto.com/").Execute();
var service=authentication.WMAuthenticateOauth(clientid,secret,“testmmm”);
IList newlist=新列表();
新增列表。添加(“国家”);
新增列表。添加(“设备”);
SearchAnalyticsQueryRequest正文=新的SearchAnalyticsQueryRequest();
body.StartDate=“2015-04-01”;
body.EndDate=“2015-05-01”;
body.Dimensions=newlist;
var result=service.Searchanalytics.Query(正文)http://www.daimto.com/Execute();
我也尝试过使用本文底部的try me进行测试。它也不会返回任何内容
奇怪的是
更新:
我终于把数据拿回来了我设定了日期
body.StartDate=“2015-09-01”body.EndDate=“2015-09-15” 我不知道这东西的数据是否有限,它只追溯到目前为止
非常感谢您在这方面的帮助。遗憾的是,这段代码在执行行中产生了与我相同的错误消息:{“error parsing NaN value.Path“”,第0行,位置0。”}NP使用新API总是很有趣:)啊,这很有意义。网站管理员工具只存储90天的数据。这是非常令人鼓舞的,你有数据!不幸的是,我最近的约会还是同样的错误。我正在使用服务帐户和密钥文件进行原始授权--我不知道这是否会有任何区别。尝试改用您的代码,但OAuth继续使用不同的端口号,因此它将永远不会“匹配已注册的重定向URI”。使用本机客户端id而不是web id进行测试。服务帐户需要被授予访问权限,我会在晚饭后查看它