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