GoolgleDrive在Windows服务中进行身份验证

时间:2017-02-22 12:23:48

标签: c# google-api google-drive-api windows-services google-api-dotnet-client

我正在创建Windows服务,并尝试使用以下代码对Google云端硬盘进行身份验证。它在控制台应用程序中工作正常,但在Windows服务中不起作用。断点使“GoogleWebAuthorizationBroker.AuthorizeAsyn”方法失控。

 using (var stream =
            new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
        {
            string credPath = System.Environment.GetFolderPath(
                System.Environment.SpecialFolder.Personal);
            credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");

            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                Scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;
            Console.WriteLine("Credential file saved to: " + credPath);
        }

0 个答案:

没有答案