我已经实现了一个使用日历API创建日历事件的c#应用。
为了使日历与我们的本地数据库保持同步,我在日历上创建了一只手表。下面的代码执行此操作,据我所知,创建了一个手表。
Channel watchChannel = new Channel()
{
Id = ConfigurationManager.AppSettings["GOOGLE_CALENDAR_WATCH_NAME"],
Type = "web_hook",
Address = ConfigurationManager.AppSettings["GOOGLE_CALENDAR_SYNC_TRIGGER_CALLBACK_URL"],
Expiration = (unixTimestamp + NINETY_DAYS_IN_SECONDS) * 1000 //milliseconds
};
try
{
logger.Debug("Creating calendar watch with the name " +
ConfigurationManager.AppSettings["GOOGLE_CALENDAR_WATCH_NAME"] + " for calendar with id " + remoteCalendarId);
Channel returnChannel = service.Events.Watch(watchChannel, remoteCalendarId).Execute();
我的问题是没有调用回调URL(我已经确认了域的所有权并为用户验证了它,这不应该成为问题)。
04.04-更多信息:
这些是在拨出电话(watchChannel)和返回对象(returnChannel)上设置的参数。
watchChannel
returnChannel
再次查看它,我还有其他几个问题:
验证码
我使用以下代码对系统用户进行身份验证,然后以“普通”非系统帐户为幌子进行操作(因为如果您实际上想查看日历)。
ServiceAccountCredential credential =
GoogleCredential.FromJson(GOOGLE_SYSTEM_USER_AUTH_INFORMATION)
.CreateScoped(Scopes)
.UnderlyingCredential as ServiceAccountCredential;
var userField =
typeof(ServiceAccountCredential).GetField("user", BindingFlags.NonPublic | BindingFlags.Instance);
userField?.SetValue(credential, GOOGLE_CALENDAR_USERNAME); //Act in the guise of the normal user GOOGLE_CALENDAR_USERNAME
service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
一时兴起,我访问了ResourceURI返回。它给了我
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
是
回调URL必须为https(证书),否则将不会被调用!