【发布时间】:2019-01-13 09:17:42
【问题描述】:
我编写了一些代码来将约会从我的桌面 C# 应用程序导出到 Google 日历。我正在使用适用于 .NET 的 Google Calendar API。
代码运行良好,除了 Web 浏览器在身份验证后总是显示错误页面(尽管如此,身份验证总是成功的)。这是我看到的消息:“无法连接。Firefox 无法在 localhost:xxx(任何端口)中建立与服务器的连接”。它发生在每个浏览器中。
我已使用以下参数在 Google 控制台中创建了我的凭据: - 使用谷歌日历 API; - 从其他 UI(不是 Web 服务器)调用 API - 访问用户数据。
这是我的代码:
public static CalendarService GetCalendarService(String[] Scopes, String userNameGoogle, String ApplicationName)
{
UserCredential credential;
using (var stream =
new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");
//MessageBox.Show(credPath);
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
userNameGoogle,
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
//MessageBox.Show("Credential file saved to: " + credPath);
}
// Create Google Calendar API service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
return service;
}
验证时会发生以下情况: See Authenticating Image
... 之后,重定向错误: See Redirection error Image
我花了好几个小时阅读帖子,但没有结果(几乎每个人都在使用网络服务器,但不是我的情况)。
拜托,你能帮帮我吗?
【问题讨论】:
-
请将截图翻译成英文。
-
您使用的是 Google.Apis.Calendar.v3 nuget 包吗?你用的是哪个版本?
-
@Chris 是的,这就是我使用的版本(Google.Apis.Calendar.v3)
标签: c# google-authentication google-api-dotnet-client