1
我正尝试使用Google Calendar API V3更新我的日历。我想从C#代码中提取日历的事件。我为Google Calendar API V3使用.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))
我收到此异常:发送直接消息或
协议异常错误
获取响应。
请帮助!
看看这张贴在这里,看看它是否可以帮助你在所有。 http://stackoverflow.com/questions/8899000/c-sharp-google-calendar-v3-2-legged-authentication-fails – HK1 2012-04-08 03:13:19