Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google日历API创建/获取事件-ASP.NET C#_C#_Asp.net_Google Api_Google Calendar Api_Google Api Dotnet Client - Fatal编程技术网

Google日历API创建/获取事件-ASP.NET C#

Google日历API创建/获取事件-ASP.NET C#,c#,asp.net,google-api,google-calendar-api,google-api-dotnet-client,C#,Asp.net,Google Api,Google Calendar Api,Google Api Dotnet Client,我想访问曾经登录到我的应用程序的用户的日历事件 使用谷歌誓言,也应该能够从我的应用程序创建事件。如何使用ASP.NET C#实现这一点 我可以使用我在访问期间创建的客户端id/密钥访问我的日历事件 以下url中的日历API项目创建过程: 欢迎提供任何帮助或示例代码 以下是我使用的代码: UserCredential-credential=GoogleWebAuthorizationBroker.AuthorizationAsync( 新客户的秘密     { ClientId=“客户端Id”

我想访问曾经登录到我的应用程序的用户的日历事件 使用谷歌誓言,也应该能够从我的应用程序创建事件。如何使用ASP.NET C#实现这一点

我可以使用我在访问期间创建的客户端id/密钥访问我的日历事件 以下url中的日历API项目创建过程:

欢迎提供任何帮助或示例代码

以下是我使用的代码:

UserCredential-credential=GoogleWebAuthorizationBroker.AuthorizationAsync(
新客户的秘密
    {
ClientId=“客户端Id”,
ClientSecret=“客户端密码”,
                },
新[]{CalendarService.Scope.CalendarReadonly},
“用户”,
取消令牌。无)。结果;
       
//创建服务。
var service=new CalendarService(new BaseClientService.Initializer()
            {
HttpClientInitializer=凭证,
ApplicationName=ApplicationName,
            });
CalendarListResource.ListRequest cal=service.CalendarList.List();
cal.MaxResults=100;
            
var calresult=cal.Execute().Items;
            
            
List ed=新列表();
  
foreach(CalendarListEntry条目在calresult中)
                {
EventsResource.ListRequest请求=service.Events.List(entry.Id);
request.TimeMin=Convert.ToDateTime(2015年1月3日);
request.showdeled=false;
request.SingleEvents=true;
request.MaxResults=200;
request.OrderBy=EventsResource.ListRequest.OrderByEnum.StartTime;
//列出事件。
Events=request.Execute();
                }
谢谢

认证:

当您运行代码时,将弹出以下代码并请求用户验证您的应用程序

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(

new ClientSecrets
 {
                ClientId = "Client-Id",
                ClientSecret = "Client-Secret",
            },
            new[] { CalendarService.Scope.CalendarReadonly },
            "user",
            CancellationToken.None).Result;
这里的键是“user”。默认情况下,库将凭据存储在计算机上的%appdata%目录中。您希望访问其数据的每个用户都必须授予您访问其帐户的权限

评论中的错误:当我使用其他电子邮件地址时,它给出了权限被拒绝的错误

我不确定您在何处提供此其他电子邮件地址,但请确保您已更改代码中的“用户”,以确保您已通过您希望访问的用户帐户的身份验证

对路径“Google.api.Auth”的评论访问出错被拒绝”

默认情况下,filedatastore将凭据存储在%appData%文件夹中。听起来您的服务器没有访问该文件夹的权限。我有一篇文章解释了如何更改它

范围:

作用域表示您需要什么类型的访问。CalendarService.Scope.CalendarReadonly仅为您提供对用户帐户的只读访问权限


注意:我不确定访问您的日历与访问用户日历是什么意思。如果您想让他们访问您的日历,您应该使用服务帐户。

通常,人们在这里发帖时会出现一个明确定义的问题。“这会引发此错误”,“当我尝试X时,它是Y,我需要它来执行Z。”“。看起来你写了一些代码,那有什么问题吗?这段代码适用于我的google帐户,它为我的日历提取事件,但当我使用其他电子邮件地址时,它会给出权限被拒绝的错误。另一个问题是,我可以在本地计算机上使用oauth使用我的帐户访问日历事件,但当将相同的代码部署到服务器时,会出现此错误。“System.AggregateException:发生一个或多个错误。-System.UnauthorizedAccessException:对路径'Google.API.Auth'的访问被拒绝”嗨,你能帮我一下吗?我在下面发布了详细信息。谢谢。使用了以下代码,但服务器没有响应。使用(var stream=newfilestream(clientSecretsJsonFilePath,FileMode.Open,FileAccess.Read)){credential=GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,作用域,“用户”,CancellationToken.None,new FileDataStore(credPath,true)).Result;}尝试为Filedatestore添加Drive.Api.Auth.Store,出现以下错误“拒绝访问路径'Drive.Api.Auth.Store'。我假设IIS没有访问该路径的权限。
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(

new ClientSecrets
 {
                ClientId = "Client-Id",
                ClientSecret = "Client-Secret",
            },
            new[] { CalendarService.Scope.CalendarReadonly },
            "user",
            CancellationToken.None).Result;