是否可以使用 AuthorizationCodeMvcApp 在 google 联系人 API 访问中进行授权?
Is it possible to use AuthorizationCodeMvcApp for authorization in google contacts API access?
我目前正在开发一个网络应用程序,用于同步用户的 google 联系人列表。
目前我可以很好地同步日历。不幸的是,在接触的情况下,同样的方法似乎并不可行。
以下是我对日历 v3 的处理方法。
public async Task<ActionResult> Index(CancellationToken cancellationToken)
{
var user = User.Identity.GetUserId();
var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
AuthorizeAsync(user, cancellationToken);
if (result.Credential != null)
{
CalendarService service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = result.Credential,
ApplicationName = "Calendar API Sample",
});
var list = service.CalendarList.List().Execute();
var calendar = list.Items.ElementAt(0);
var events = service.Events.List(calendar.Id).Execute();
foreach (var e in events.Items)
{
try {
EventLoot.data.Entities.Event model = new EventLoot.data.Entities.Event();
model.User_id = User.Identity.GetUserId();
model.Venue = e.Location != null ? e.Location : "" ;
model.Name = e.Summary;
model.Date = DateTime.Today;
model.start_date = e.Start.DateTime;
model.end_date = e.End.DateTime;
model.start_time = e.Start.DateTime.Value.TimeOfDay;
model.end_time = e.End.DateTime.Value.TimeOfDay;
dbcontext.Events.Add(model);
dbcontext.SaveChanges();
}
catch (Exception a)
{
Console.Write(a);
}
}
list.ToString();
return View("index");
}
我喜欢这种方法,因为 DataStore 负责确保我有一个刷新令牌。这种方法是否也适用于 Google 联系人?如果有怎么办?
不幸的是,Google 联系人支持旧的 GData 协议,API 在新的 Google APIs .NET 客户端库中没有等效的库.
但是...我也有好消息,看看这个帖子 - How to create a ContactsService using Google Contact API v3 with OAuth v2 UserCredentials。
您可以在日历范围之外为联系人API、“https://www.google.com/m8/feeds/”添加新的范围,并且在用户完成身份验证后,您可以使用存储在DataStore 中的令牌与GData API 联系人。
我目前正在开发一个网络应用程序,用于同步用户的 google 联系人列表。
目前我可以很好地同步日历。不幸的是,在接触的情况下,同样的方法似乎并不可行。
以下是我对日历 v3 的处理方法。
public async Task<ActionResult> Index(CancellationToken cancellationToken)
{
var user = User.Identity.GetUserId();
var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
AuthorizeAsync(user, cancellationToken);
if (result.Credential != null)
{
CalendarService service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = result.Credential,
ApplicationName = "Calendar API Sample",
});
var list = service.CalendarList.List().Execute();
var calendar = list.Items.ElementAt(0);
var events = service.Events.List(calendar.Id).Execute();
foreach (var e in events.Items)
{
try {
EventLoot.data.Entities.Event model = new EventLoot.data.Entities.Event();
model.User_id = User.Identity.GetUserId();
model.Venue = e.Location != null ? e.Location : "" ;
model.Name = e.Summary;
model.Date = DateTime.Today;
model.start_date = e.Start.DateTime;
model.end_date = e.End.DateTime;
model.start_time = e.Start.DateTime.Value.TimeOfDay;
model.end_time = e.End.DateTime.Value.TimeOfDay;
dbcontext.Events.Add(model);
dbcontext.SaveChanges();
}
catch (Exception a)
{
Console.Write(a);
}
}
list.ToString();
return View("index");
}
我喜欢这种方法,因为 DataStore 负责确保我有一个刷新令牌。这种方法是否也适用于 Google 联系人?如果有怎么办?
不幸的是,Google 联系人支持旧的 GData 协议,API 在新的 Google APIs .NET 客户端库中没有等效的库.
但是...我也有好消息,看看这个帖子 - How to create a ContactsService using Google Contact API v3 with OAuth v2 UserCredentials。
您可以在日历范围之外为联系人API、“https://www.google.com/m8/feeds/”添加新的范围,并且在用户完成身份验证后,您可以使用存储在DataStore 中的令牌与GData API 联系人。