【问题标题】:Coordinate API OAuth2 authentication with refresh token使用刷新令牌协调 API OAuth2 身份验证
【发布时间】:2015-01-08 05:49:35
【问题描述】:
我正在寻找使用 OAuth2 和现有刷新令牌验证坐标 API 的示例代码。我正在线程Google Coordinate OAuth2 with Service Account 中寻找类似的东西。我已经尝试过该代码 sn-p 但由于 dll 冲突,我遇到了一些问题。从 nuget 库看来,Google.Apis.Authentication.OAuth2 似乎已被弃用,我们应该改用 Google.Apis.Auth。
因此,如果有人可以提供与Google.Apis.Auth 一起使用的示例代码,那就太好了。
请帮忙。
【问题讨论】:
标签:
c#
asp.net
api
oauth-2.0
coordinate
【解决方案1】:
我可以通过尝试不同的组合来找到解决方案。添加示例代码,我认为这将有助于寻找类似解决方案的人。
using Google.Apis.Auth.OAuth2;
using Google.Apis.Coordinate.v1;
using Google.Apis.Coordinate.v1.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using (var stream = new FileStream(@"client_secret.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
new[] { CoordinateService.Scope.Coordinate },
"user", CancellationToken.None,new FileDataStore(folder));
}
var service = new CoordinateService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "appname",
});
var list = await service.Location.List("teamid", "team@mailid.com", 2000).ExecuteAsync();
希望这会有所帮助。
谢谢,
MG