음, 더 많이 읽은 후에이 예외의 이유를 발견했습니다.
https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtAuthorization?#helpme
잘못된 그랜트
https://developers.google.com/accounts/docs/OAuth2#expiration
: 새로 고침 토큰 제한이 초과되었습니다 (기본값은 25). 그게 전부입니다.
이 문서에 따르면 현재 Google 사용자 계정 당 25 개의 토큰 제한이 있습니다. 사용자 계정에 25 개의 유효한 토큰이있는 경우 다음 인증 요청이 성공하지만 사용자가 볼 수있는 경고없이 가장 오래된 토큰이 자동으로 무효화됩니다.
응용 프로그램이 유효하지 않은 새로 고침 토큰을 사용하려고 시도하면 invalid_grant 오류 응답이 반환됩니다. OAuth 2.0 클라이언트와 Google 애널리틱스 계정의 각 고유 한 쌍의 한도는 25 개의 새로 고침 토큰입니다 (이 한도는 변경 될 수 있습니다).
알기로 새로 고침 토큰의 수를 25 개로 제한하지만 제한을 초과해야 할 때 수행 할 작업을 말하지 않습니다. Arghhh ... 나는 그 한계를 우회하는 방법을 실험하고 해결책을 찾았다. 실제로 응용 프로그램 풀을 재활용하면 문제를 해결할 수 있습니다 (물론 다음 25 한계에 도달 할 때까지). 우리는 수동으로 IIS 또는 명령을 실행하여 AppPool을 재활용 할 수
c:\Windows\System32\inetsrv\appcmd.exe recycle apppool /apppool.name:AppPoolName
당신은 매일 밤 또는 매 시간마다, 어떤 실행하는 명령을 예약 할 수 있습니다 ...
그러나 나는이 프로그램 솔루션이 발견
재정의 컨트롤러에 OnException 방법을
는
protected override void OnException(ExceptionContext filterContext)
{
if (filterContext.ExceptionHandled) return;
// Log exception details
Global.LogException(filterContext.Exception, EventLogEntryType.Error);
if (filterContext.Exception.Message.Contains("invalid_grant"))
{
// Invalid Grant: The refresh token limit has been exceeded (default is 25).
// https://developers.google.com/accounts/docs/OAuth2#expiration
// https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtAuthorization?#helpme
Global.RecycleAppPool();
Global.LogException(new Exception("AppPool has been recycled"), EventLogEntryType.Information);
Response.Redirect("Index");
}
var actionName = filterContext.RouteData.Values["action"].ToString();
// Return friendly error message
var errorMessage = string.Format("Action {0} failed with error: {1}. Please try again.", actionName, filterContext.Exception.Message);
filterContext.Result = Content(errorMessage);
filterContext.ExceptionHandled = true;
base.OnException(filterContext);
}
는 에게 RecycleAppPool가 (이 작업이 빠르고 다음과 같이 정의된다
은 좋아하지 (그것은 MVC의 앱입니다) 다시 시작 IIS는 :) : AppPool을 재활용하고, 기록하고, 한도 :
public static void RecycleAppPool()
{
ServerManager serverManager = new ServerManager();
ApplicationPool appPool = serverManager.ApplicationPools["Homepage"];
if (appPool != null)
{
if (appPool.State == ObjectState.Stopped) appPool.Start();
else appPool.Recycle();
}
}
그래서, invalid_grant 예외의 경우를 제외하고는 "삼켜" 새로 고침 토큰이 재설정됩니다. 희망이 도움이됩니다.
몇 가지 문제가 있으면 알려주십시오.
이것은 정확히 나를위한 것입니다. NTP와 동기화 된 다음 IIS를 다시 시작했습니다. http://nefaria.com/2013/03/configure-windows-server-20082012-to-sync-with-internet-time-servers/ – pharophy