我在嘗試運行我的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#代碼後使用。請求中的重定向URI:http:// localhost:12349/authorize /與註冊的重定向URI不匹配
這裏是我的代碼:
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 = "[email protected]", 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();
}
}
這是我的重定向的URI在我的Google代碼Console項目。
Redirect URIs: http://localhost:7744/authorize/
而這是瀏覽器中顯示的錯誤消息。
我找不到任何辦法來解決這一問題。一些幫助將是可觀的。我也搜索了所有在stackoverflow中發佈的帖子。但我找不到解決方案。
端口號不匹配,並且端口號是HTTP URI的身份的重要部分。 –
@Damien_The_Unbeliever我知道。但我沒有在我的控制檯應用程序中定義任何重定向uri。如何定義這一點。 –
@Damien_The_Unbeliever如何在匹配的情況下從控制檯應用程序中定義redirect uri? –