我正在使用Google日历API,以检索指定日历的所有事件。在设置我的凭据并调用以下内容后,获取所有日历的列表:
var test = service.Calendars.Get(id).Execute();
Execite()正在调用谷歌服务器,但我没有得到该通话的响应。并且它处于这种空闲状态。
public static ServiceAccountCredential Authenticate() {
string serviceAccountEmail = "...@developer.gserviceaccount.com";
string keyFilePath = @"filepath";
// what googleApi features to access
_scopes = new string[]
{
CalendarService.Scope.Calendar, // Manage your calendars
CalendarService.Scope.CalendarReadonly // View your Calendars
};
var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = _scopes
}.FromCertificate(certificate));
return credential;
}
public class GoogleCalenderRepository
{
ServiceAccountCredential _credentials;
public GoogleCalenderRepository()
{
_credentials = GoogleServiceAccountAuthentication.Authenticate();
}
// use async and await
public string RoomAvailability()
{
CalendarService service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = _credentials,
ApplicationName = "My Project",
});
var calender = service.Calendars.Get("@...group.calendar.google.com").Execute();
return null;
}
}
编辑:当我在输出屏幕中调用Execute()时,我得到:
线程0x13f4已退出,代码为0(0x0)