小编Han*_*ain的帖子

请求中的重定向URI:http:// localhost:12349/authorize /与注册的重定向URI不匹配

我在尝试运行我的c#控制台应用程序时收到此错误...我正在尝试调用google calender api v3来获取日历并将事件添加到日历中.根据google-api-dotnet-client的示例代码,我这样做.(https://code.google.com/p/google-api-dotnet-client/source/browse/Calendar.VB.ConsoleApp/Program .vb?repo = samples)这是vb.net代码.我将它转换为c#代码后使用此示例.

这是我的代码:

class Program
{
    static void Main(string[] args)
    {
        try
        {
            new Program().Run().Wait();
        }
        catch (AggregateException ex)
        {
            foreach (var e in ex.InnerExceptions)
            {
                Console.WriteLine("ERROR: " + e.Message);
            }
        }
    }

    private async Task Run()
    {
        UserCredential credential;
        IList<string> scopes = new List<string>();

        CalendarService service;
        scopes.Add(CalendarService.Scope.Calendar);


        using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
        {
            // problem occuring during executing this statement.
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                scopes,
                "user", CancellationToken.None, new …
Run Code Online (Sandbox Code Playgroud)

c# google-calendar-api oauth-2.0 google-api-dotnet-client

6
推荐指数
1
解决办法
9947
查看次数

如何使用access_token创建CalendarService对象?

我正在尝试使用.net客户端使用谷歌日历v3 api.我正在采用混合方法.我只使用http post请求使用oauth2授权我的应用程序,我得到了access_token.但作为日历v3 api的.net客户端,我需要制作一个日历服务参考.我需要找到任何方法来使用我的令牌获取该服务引用.看看这段代码:

Event event = new Event()
{
  Summary = "Appointment",     
};

Event recurringEvent = service.Events.Insert(event, "primary").Fetch();
// here "service" is authenticate calendarservice instance.

Console.WriteLine(recurringEvent.Id);
Run Code Online (Sandbox Code Playgroud)

这是获取经过身份验证的日历服务实例的代码:

 UserCredential credential;
 using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
 {
      credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                new[] { CalendarService.Scope.Calendar },
                "user", CancellationToken.None, new FileDataStore("something"));
 }

  // Create the service instance.
  var service = new CalendarService(new BaseClientService.Initializer()
  {
          HttpClientInitializer = credential,
          ApplicationName = "Books API Sample",
  });
Run Code Online (Sandbox Code Playgroud)

此代码根据Google.Apis.Auth.OAuth2显示授权代码流,然后使用该凭据进行服务引用.实际上,这是一个管理授权代码流的辅助工具.为了清楚起见,我没有使用这个程序.(这个助手实用程序).我正在尝试在核心级别执行所有操作,这意味着我已通过简单的HTTP Web请求手动创建了授权代码流.我完全完成了授权.现在我有那个用户access_token.

现在我的问题是如何仅使用该access_token手动创建此服务实例.如果有什么事打扰你,请随时提出任何问题.

注意 - 我知道如何创建CalendarService实例: …

google-calendar-api oauth-2.0 google-api-dotnet-client

6
推荐指数
2
解决办法
2164
查看次数