【问题标题】:.net and google authentication.net 和谷歌身份验证
【发布时间】:2015-01-05 16:03:13
【问题描述】:

我使用过使用谷歌日历的谷歌示例。我的应用程序运行良好,直到他们最近更改了 API。我发现他们的文档有点压倒性而且不是很有用。我用过这个example

我收到以下错误

未处理的异常类型: Google.Apis.Auth.dll 中发生 System.InvalidOperationException'

附加信息:应设置至少一个客户端机密(已安装或 Web)

我不知道客户的秘密是什么,也不知道他们在说什么。我已经搜索了该短语,但没有任何信息返回。什么是客户端密码,如何设置?

这是我收到错误的代码行。

 credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets, scopes, "user", CancellationToken.None,
                    New FileDataStore("CalendarSample")).Result

我有他们为我设置的 json 文件,它似乎正在读取它。我确定我应该修改那个文件,但我找不到任何有确切说明的东西。

任何帮助都会很棒。我最终要做的只是从谷歌日历中添加和删除条目。

谢谢

【问题讨论】:

  • 你试过并得到解决方案了吗?

标签: .net google-calendar-api google-oauth google-api-dotnet-client


【解决方案1】:

我假设您在这里使用的是 Oauth2。

使用金块包Google.Apis.Calendar.v3 Client Library向谷歌日历进行身份验证的基本代码

string clientId = "";//From Google Developer console https://console.developers.google.com
 string clientSecret = "";//From Google Developer console https://console.developers.google.com
 string userName = ""//  A string used to identify a user.
 string[] scopes = new string[] {
    CalendarService.Scope.Calendar, // Manage your calendars
    CalendarService.Scope.CalendarReadonly // View your Calendars
 };

// 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("Daimto.GoogleCalendar.Auth.Store")).Result;

通过身份验证后,您可以使用创建日历服务来访问谷歌日历

// Create the service.
    CalendarService service = new CalendarService(new BaseClientService.Initializer() {
        HttpClientInitializer = credential,
        ApplicationName = "Calendar API Sample",
    });

从教程Google Calendar API with C# 中提取的代码会保持最新。

【讨论】:

  • 我从来没有得到答案。
猜你喜欢
  • 1970-01-01
  • 2012-09-20
  • 2020-08-15
  • 2018-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-20
相关资源
最近更新 更多