【发布时间】:2014-12-01 21:30:33
【问题描述】:
尝试对 Google 坐标 api 进行身份验证。尝试使用服务帐户进行服务帐户身份验证,并使用this 问题发布堆栈流。找到this anwer 并很好地描述了我的问题。
现在的问题是库 used 已被弃用。无法执行解决方案说。
var auth = new OAuth2Authenticator<WebServerClient> (provider, GetAuthorization);
// Create the service.
var service = new CoordinateService(new BaseClientService.Initializer()
{
Authenticator = auth
});
任何人都可以提出一种方法来实现上述代码。我已经为 Google APIs OAuth2 客户端库安装了新版本。但是没有找到类似的代码。
我可以使用下面的代码 sn-p 来读取 api
using Google.Apis.Auth.OAuth2;
using Google.Apis.Coordinate.v1;
using Google.Apis.Coordinate.v1.Data;
using Google.Apis.Services;
using (var stream = new FileStream(System.Web.HttpContext.Current.Server.MapPath(@"../client_secret.json"), FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
new[] { CoordinateService.Scope.Coordinate },
"user", CancellationToken.None);
}
// Create the service.
var service = new CoordinateService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "test",
});
//builds with time last day 12 am
var locationReq = service.Location.List(teamId, workerMail, (ulong)DateTime.Today.AddDays(-1).ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
var locationResult = locationReq.Execute();
但是这个方法第一次需要重定向。在我的场景中,我无法做到这一点。所以需要一个离线解决方案。
【问题讨论】:
标签: c# .net google-api google-oauth google-api-dotnet-client