我正在尝试将MySQL数据库中的某些议程推送到Google日历帐户。 我使用“服务帐户OAuth2”方式与Google提供的日历服务进行通信。 此外,我使用Fiddler来验证我发送的请求和我收到的响应是否构建良好。
好了,现在让我解释一下我的问题:当我尝试在我的谷歌日历上写一些东西时,请求和回复绝对没问题(你可以信任我,如果有人愿意,我会稍后再举一些例子)但是我谷歌日历网站上看不到任何变化! 这真的很奇怪......我很快就看到了访问控制规则,但它们看起来也很好。
我需要有人帮我正确理解。
(对不起,如果我现在没有时间展示一些例子,但我不认为他们需要它们,因为谷歌服务器必须回应。在不到16小时内会有例子,我承诺;-))
亲切的问候, 布鲁诺
以下是我如何连接服务的示例:
public const string APP_NAME = "My App Name";
public const string EMAIL_ADDRESS = "xxxxxxxxxxxxxxxxx@developer.gserviceaccount.com";
public const string PRIV_KEY_PATH = @"C:\xxxxxxxxxxxxxxxxxxxxxxxxxx-privatekey.p12";
public const string PRIV_KEY_SECRET = "notasecret";
public const string SIMPLE_API_KEY = "xxxxxxxxxxxxxxxxxx";
public const string SCOPE_CALENDAR = "https://www.googleapis.com/auth/calendar";
var certificate = new X509Certificate2(PRIV_KEY_PATH, PRIV_KEY_SECRET, X509KeyStorageFlags.Exportable);
var privateKey = certificate.Export(X509ContentType.Cert);
var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
{
ServiceAccountId = EMAIL_ADDRESS,
Scope = SCOPE_CALENDAR
};
var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);
CalendarService service;
try
{
service new CalendarService(new BaseClientService.Initializer()
{
Authenticator = auth,
ApplicationName = APP_NAME,
ApiKey = SIMPLE_API_KEY,
DefaultExponentialBackOffPolicy = BaseClientService.ExponentialBackOffPolicy.None
});
}
catch (GoogleApiException ex)
{
MessageBox.Show(ex.Message);
return null;
}
以下是我尝试创建事件的示例:
try
{
List<EventAttendee> attendees = new List<EventAttendee>();
attendees.Add(new EventAttendee
{
Email = "bruno.boi@voice.modal.be",
DisplayName = "Bruno Boi"
});
attendees.Add(new EventAttendee
{
Email = "david.boi@voice.modal.be",
DisplayName = "David Boi",
});
Event testevent = service.Events.Insert(
new Event
{
Summary = "Pétanque exceptionnelle et BBQ",
Description = "Une pétanque accompagnée d'un excellent BBQ, entre friends",
//Location = "In da place",
Start = new EventDateTime
{
//Date = "2013-07-12",
DateTime = "2013-07-12T08:00:00.000",
TimeZone = "Europe/Brussels"
},
End = new EventDateTime
{
//Date = "2013-07-13",
DateTime = "2013-07-13T08:00:00.000",
TimeZone = "Europe/Brussels"
},
Attendees = attendees,
},
"primary"
).Execute();
}
catch (GoogleApiException ex) { MessageBox.Show(ex.Message); }
我尝试使用google api reference documentation的“试用”功能。我的所有测试都成功了。我不明白为什么当我用我的应用程序尝试相同的请求时服务器不写我的更改...
以下是我使用我的代码构建的请求以及我用Fiddler捕获的请求:
{
"summary": "Pétanque exceptionnelle et BBQ",
"attendees": [
{
"displayName": "Bruno Boi",
"email": "bruno.boi@voice.modal.be"
},
{
"displayName": "David Boi",
"email": "david.boi@voice.modal.be"
}
], "start": {
"timeZone": "Europe/Brussels",
"dateTime": "2013-07-12T08:00:00.000"
},
"description": "Une pétanque accompagnée d'un excellent BBQ, entre friends",
"end": {
"timeZone": "Europe/Brussels",
"dateTime": "2013-07-13T08:00:00.000"
}
}
服务器收到的响应:
{
"kind": "calendar#event",
"etag": "\"FArtfq34fz_gKzsAfdahfuTRgehbdzg/MT2435T3GEgzefgzTQwMjM5MDAwMA\"",
"id": "vl135egrg635yoa29o8k",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=dmw1bjMzY3ergZTY54thtyuHBTrsdfHzRTht4EhE3OTQ3NTg2LW12OXJ1MzRjdWVqcDEzZDNoMTZ0cmpzcXR2ODYxbjZyQGRldmVsb3Blci5nc2VydmljZWFjY291bnQuY29t",
"created": "2013-07-12T06:10:02.000Z",
"updated": "2013-07-12T06:10:02.390Z",
"summary": "Pétanque exceptionnelle et BBQ",
"description": "Une pétanque accompagnée d'un excellent BBQ, entre friends",
"creator": {
"email": "xxxxxxxhiddenbymexxxxxxxxxxxx@developer.gserviceaccount.com",
"self": true
},
"organizer": {
"email": "xxxxxxxhiddenbymexxxxxxxxxxxx@developer.gserviceaccount.com",
"self": true
},
"start": {
"dateTime": "2013-07-12T06:00:00Z",
"timeZone": "Europe/Brussels"
},
"end": {
"dateTime": "2013-07-13T06:00:00Z",
"timeZone": "Europe/Brussels"
},
"iCalUID": "vl135egrg635yoa29o8k@google.com",
"sequence": 0,
"attendees": [
{
"email": "bruno.boi@ohyeah.be",
"displayName": "Bruno Boi",
"responseStatus": "needsAction"
},
{
"email": "david.boi@ohyeah.be",
"displayName": "David Boi",
"responseStatus": "needsAction"
}
],
"reminders": {
"useDefault": true
}
}
感谢您帮助我!