Han*_*ain 6 c# google-calendar-api oauth-2.0 google-api-dotnet-client
我在尝试运行我的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 FileDataStore("Calender.SampleApp") );
}
BaseClientService.Initializer initializer = new BaseClientService.Initializer();
initializer.HttpClientInitializer = credential;
initializer.ApplicationName = "C# Calendar Sample";
service = new CalendarService(initializer);
Event newEvent = new Event();
newEvent.Summary = "Appointment";
newEvent.Description = "Need to meet my Uncle";
IList<EventReminder> reminders = new List<EventReminder>();
reminders.Add(new EventReminder { Method = "sms", Minutes = 10 });
newEvent.Reminders = new Event.RemindersData { UseDefault = false, Overrides = reminders };
newEvent.Recurrence = new String[] { "DTSTART;TZID=Bangladesh Standard Time:20140124T163000;RRULE:FREQ=DAILY" };
IList<EventAttendee> attendees = new List<EventAttendee>();
attendees.Add(new EventAttendee { Email = "hannan.cse.m@gmail.com", Organizer = true, DisplayName = "Hannan" });
newEvent.Attendees = attendees;
newEvent.GuestsCanInviteOthers = false;
newEvent.GuestsCanModify = false;
newEvent.GuestsCanSeeOtherGuests = false;
newEvent.Location = "Dhaka, Bangladesh";
newEvent.Start = new EventDateTime { DateTime = DateTime.Now, TimeZone = "Bangladesh Standard Time" };
Event recurringEvent = service.Events.Insert(newEvent, "primary").Execute();
var list = await service.CalendarList.List().ExecuteAsync();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在GoogleDevelopers Console项目中的重定向URI.
Redirect URIs: http://localhost:7744/authorize/
Run Code Online (Sandbox Code Playgroud)
这是浏览器中显示的错误消息.

我找不到任何方法来解决这个问题.一些帮助将是值得的.我还在stackoverflow中搜索所有已发布的帖子.但我找不到它的解决方案.
SKD*_*SKD 23
我认为您在GoogleDevelopers Console中"创建客户端ID"时做错了什么.确保您已在应用程序类型中选择"已安装的应用程序"以从控制台应用程序访问您的项目.
看看附图.根据请求类型,您必须在Google Developers Console中的已注册应用程序中创建clientid和credintials.
在进行身份验证时,您无需在控制台应用程序中定义重定向uri.

| 归档时间: |
|
| 查看次数: |
9947 次 |
| 最近记录: |