Pau*_*ers 5 .net c# google-api google-api-dotnet-client google-api-webmasters
我想知道是否有人比我更进一步,通过 .Net 使用 Google 网站管理员工具 API 的新搜索分析功能?
我正在使用 Google.Apis.Webmasters.v3 Nuget 包,并且已经进行了身份验证和连接(使用服务帐户)
但是,我很难通过搜索分析获得任何结果。
我在网上找不到任何代码示例,所以在https://developers.google.com/resources/api-libraries/documentation/webmasters/v3/csharp/latest/annotated.html和很多类信息的指导下的猜测。
这是我正在使用的代码:
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();
Run Code Online (Sandbox Code Playgroud)
当我收到“发生错误,但错误响应无法反序列化”时,它运行正常,直到执行方法。异常详情如下...
Newtonsoft.Json.JsonReaderException {“解析 NaN 值时出错。路径 '',第 0 行,位置 0。”}
任何帮助或代码示例将不胜感激!
这可以编译,但没有为我返回任何数据。
授权:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
要求
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();
Run Code Online (Sandbox Code Playgroud)
我还尝试使用本页底部的“尝试我”进行测试。它也不返回任何东西。
奇怪的 API 这个。
更新:
我终于得到了数据,我将日期设置为
body.StartDate = "2015-09-01";
body.EndDate = "2015-09-15";
我不知道这个东西的数据是否有限,只能追溯到到目前为止。
| 归档时间: |
|
| 查看次数: |
1182 次 |
| 最近记录: |