1

我已按照此处的教程使用 Google 登录并在 ASP.Net MVC 应用程序中访问 GMail API。

但是在这一行我的程序被卡住了,我的意思是没有响应,我想来自谷歌服务器。

var result = await new AuthorizationCodeMvcApp(this, new AppAuthFlowMetadata()).
                AuthorizeAsync(cancellationToken);

我不知道为什么授权用户请求需要时间。

4

2 回答 2

1
  • 主要问题是asyncawait关键字。这些关键字虽然在 VS2010 中被支持为CTP,但在 .Net Framework 4 的 VS 2010 中实际上并不适用。
  • 这些关键字最终随 .Net Framework 4.5 发布,完全支持 VS 2012。
  • 因此,要完成这项工作,我必须将我的解决方案移植到 VS 2012。

很简单的解决方案,我想,我应该早点想出来:(

于 2014-08-26T08:17:16.860 回答
0

我不确定你的具体问题是什么。我已使用以下内容访问 Gmail API。

// Create OAuth Credential.
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    new ClientSecrets
    {
        ClientId = "CLIENT_ID",
        ClientSecret = "CLIENT_SECRET"
    },
    new[] { GmailService.Scope.GmailModify },
    "me",
    CancellationToken.None).Result;
// Create the service.
var service = new GmailService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Draft Sender",
});
ListDraftsResponse draftsResponse = service.Users.Drafts.List("me").Execute();
IList<Draft> drafts = draftsResponse.Drafts;
于 2014-07-18T18:42:29.130 回答