小编S.R*_*nth的帖子

Google API V 3.0 .Net库和Google OAuth2如何处理刷新令牌

在我的应用程序中,我使用Google API V 3.0 .Net库与Google OAuth2同步Google日历和Outlook日历.我使用下面的代码来获取Google.Apis.Calendar.v3.CalendarService服务对象.在身份验证期间,我存储了Json文件,并从中请求了Google.Apis.Auth.OAuth2.UserCredential对象.

private Google.Apis.Auth.OAuth2.UserCredential GetGoogleOAuthCredential()
{
    GoogleTokenModel _TokenData = new GoogleTokenModel();
    String JsonFilelocation = "jsonFileLocation;
    Google.Apis.Auth.OAuth2.UserCredential credential = null;
    using (var stream = new FileStream(JsonFilelocation, FileMode.Open,
                    FileAccess.Read))
    {
        Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.Folder = "Tasks.Auth.Store";
        credential = Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(
        Google.Apis.Auth.OAuth2.GoogleClientSecrets.Load(stream).Secrets,
        new[] { Google.Apis.Calendar.v3.CalendarService.Scope.Calendar },
        "user",
        CancellationToken.None,
        new FileDataStore("OGSync.Auth.Store")).Result;
    }
    return credential;
}
Run Code Online (Sandbox Code Playgroud)

请求服务对象代码是:

Google.Apis.Calendar.v3.CalendarService _V3calendarService = new Google.Apis.Calendar.v3.CalendarService(new Google.Apis.Services.BaseClientService.Initializer()
{
HttpClientInitializer = GetGoogleOAuthCredential(),
ApplicationName = "TestApplication",
});
Run Code Online (Sandbox Code Playgroud)

上面的代码可以很好地获取Calendarservice对象.我的问题是,我的Json文件有刷新和访问令牌.当访问令牌过期时,上述代码如何处理刷新令牌以获取服务?因为我需要经常调用Calendarservice对象,所以我喜欢为calenderService对象实现单例模式.如何在不经常调用GetGoogleOAuthCredential的情况下获取Calendarservice?任何帮助/指导表示赞赏.

c# google-calendar-api google-api google-oauth google-api-dotnet-client

7
推荐指数
2
解决办法
1万
查看次数

UI自动化白色框架"检测到NonComVisibleBaseClass"异常

我正在测试一个加载powerpoint(.ppt或.pptx)文件的应用程序插入它.当文件加载到应用程序内部时,应用程序给出了类似powerpoint的感觉和一些额外的设置.当我尝试自动化应用程序时,我单击一个按钮将powerpoint文件加载到应用程序中.加载过程后,白色框架无法继续播放.

当我再次重新启动相同的测试时,我得到了" 检测到NonComVisibleBaseClass "异常.

我只能在重新启动整个应用程序后继续我的测试.有人遇到过这种问题吗?您的答案对我的测试非常有帮助.

automated-tests white-framework ui-testing ui-automation

5
推荐指数
1
解决办法
4152
查看次数