谷歌C#客户端库得到更新凭证 [英] Google C# client library to get refresh token

查看:114
本文介绍了谷歌C#客户端库得到更新凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的previous code与图书馆的帮助。

  UserCredential凭证= GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(流).Secrets,
                    新的[] {
                    GmailService.Scope.GmailCompose,GmailService.Scope.GmailModify,GmailService.Scope.GmailReadonly
                    },
                用户,
                CancellationToken.None
                );

我在ASP.NET MVC应用4用这个。在这个声明中,它挂起浏览器。我试图把日志,也不例外,没有进一步的执行完成。我看着这个的问题,因为它是异步操作,我切换到Visual Studio 2013年。但还是同样的事情。

更新code:

  UserCredential凭证=等待GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.Load(流).Secrets,
                新的[] {
                GmailService.Scope.GmailCompose,GmailService.Scope.GmailModify,GmailService.Scope.GmailReadonly
                },
            用户,
            CancellationToken.None
            );


解决方案

该控制器还必须标有异步和返回任务即。

 公共异步任务< IHttpActionResult>得到(字符串标记){
    //你的code在这里
}

This was my previous code with the help of library.

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                    new[] { 
                    GmailService.Scope.GmailCompose, GmailService.Scope.GmailModify, GmailService.Scope.GmailReadonly
                    },
                "user", 
                CancellationToken.None
                ) ;

I'm using this in ASP.NET MVC 4 application. At this statement, it hangs the browser. I tried putting logs, no exception and no further execution is done. I looked at this question, and since it is asynchronous operation, I switched to Visual Studio 2013. But still the same thing.

Updated code:

UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.Load(stream).Secrets,
                new[] { 
                GmailService.Scope.GmailCompose, GmailService.Scope.GmailModify, GmailService.Scope.GmailReadonly
                },
            "user", 
            CancellationToken.None
            ) ;

解决方案

The controller must also be marked with async and return a Task i.e.

public async Task<IHttpActionResult> get(string token){
    //your code here
}

这篇关于谷歌C#客户端库得到更新凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆