我正在创建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);
}