Gmail API .NET WebWebAuthorizationBroker.AuthorizeAsync使浏览器等待

时间:2017-04-11 23:23:11

标签: c# google-oauth gmail-api google-api-dotnet-client google-oauth2

我正在使用.NET库来访问Gmail API。我基本上只是在做quickstart guide它确实有效,但在网络浏览器中授权后,浏览器仍然在旋转/等待。我希望浏览器窗口关闭,或者给出一条消息说已经提供了访问令牌,但它只是在光标旋转时保持空白。这是我的代码:

private async Task Authorize()
{
    string[] Scopes = { GmailService.Scope.MailGoogleCom };
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        new ClientSecrets
        {
            ClientId = "<myclientid>.apps.googleusercontent.com",
            ClientSecret = "<myclientsecret>"
        },
        Scopes,
        UserEmail,
        CancellationToken.None,
        new FileDataStore("Somepath"));

    // Create Gmail API service.
    var service = new GmailService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = String.Format("MyCompany-{0}-v{1}", Constants.szAppName, Constants.VERSION),
    });

    // Define parameters of request.
    UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");

    // List labels.
    IList<Google.Apis.Gmail.v1.Data.Label> labels = request.Execute().Labels;
    Console.WriteLine("Labels:");
    if (labels != null && labels.Count > 0)
    {
        foreach (var labelItem in labels)
        {
            Console.WriteLine("{0}", labelItem.Name);
        }
    }
    else
    {
        Console.WriteLine("No labels found.");
    }
}

即使它提供了访问令牌和功能,我想通过浏览器完成/停止来清理它。知道我做错了吗?

0 个答案:

没有答案