[英]Google Calendar API V3
我正在尝试使用Google Calendar API V3更新我的日历。 我想从C#代码中获取日历事件。 我正在将.Net库用于Google Calendar API V3。
由于某种原因,我无法批准我的请求。 我试图遵循可用的代码示例,但徒劳。 以下是我用来授权请求的代码段:
private void GetEvents()
{
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description,MyClientId, MySecurityId);
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
CalendarService myService = new CalendarService(auth);
try
{
Events result = myService.Events.List(MyCalendarId).Fetch();
if (result.Items.Count > 0)
{
}
}
catch (Google.GoogleApiRequestException ex)
{
//throw ex;
}
}
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
IAuthorizationState state = new AuthorizationState(new[] { "https://www.googleapis.com/auth/calendar.readonly" });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
if (!string.IsNullOrEmpty(refreshToken)) // refreshToken you stored in step 4
{
try
{
state.RefreshToken = refreshToken;
if (arg.RefreshToken(state)) // This is calling out to the OAuth servers with the refresh token getting back a session token, returns true if successful.
{
if (state.RefreshToken != refreshToken) // if the refresh token has changed, save it.
{
//PersistRefreshToken(authorization.RefreshToken);
}
return state; // Retain the authorization state, this is what will authenticate your calls.
}
}
catch (ProtocolException ex) { throw ex; }
}
return state;
}
if (arg.RefreshToken(state))
则会收到此异常:
协议异常发送直接消息时出错或
得到回应。
请帮忙!!!
您是在Web服务器上还是在本机应用程序中使用它? 您拥有的这段代码仅适用于本机应用程序,因此可能是您的麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.