Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我的谷歌账户认证失败?_C#_.net_Google Sheets_Google Authentication_Google Api Dotnet Client - Fatal编程技术网

C# 为什么我的谷歌账户认证失败?

C# 为什么我的谷歌账户认证失败?,c#,.net,google-sheets,google-authentication,google-api-dotnet-client,C#,.net,Google Sheets,Google Authentication,Google Api Dotnet Client,我已经创建了一个刮削应用程序(C#),它将结果写入一个私有的Google工作表 当我在调试模式下运行应用程序时,它会按预期工作并进行身份验证。 但是,当我将其作为任务运行时,身份验证在此失败 using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) { string credPath = Environment.G

我已经创建了一个刮削应用程序(C#),它将结果写入一个私有的Google工作表

当我在调试模式下运行应用程序时,它会按预期工作并进行身份验证。 但是,当我将其作为任务运行时,身份验证在此失败

 using (var stream =
            new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
        {
            string credPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-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);
        }
我有一个credentials.json文件设置为在项目中始终复制,并在编译时将其复制到bin/debug和bin/release文件夹中

我得到的错误(仅当在任务计划程序中运行时)是

Unhandled Exception: System.IO.FileNotFoundException: Could not find file 
'C:\WINDOWS\system32\credentials.json'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, 
   Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, 
   FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean 
   bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at ScreenScraper.Program.AuthorizeGoogleApp() in 
   C:\Users\xxx\Documents\Visual Studio 
   2017\Projects\ScreenScraper\ScreenScraper\Program.cs:line 74
   at ScreenScraper.Program.Main(String[] args) in C:\Users\xxx\Documents\Visual 
   Studio 2017\Projects\ScreenScraper\ScreenScraper\Program.cs:line 38


然后我将credentials.json复制到C:\WINDOWS\system32\中,但仍然收到错误

在操作中将可选启动更改为文件夹路径。
Actions>Edit>Program/script=YOurGoogle.exe>Start in(可选)>例如C:\Users\Me\

权限问题可能?可能-我已授予文件夹的完全读取权限-相同错误我建议您选择其他路径tham Environment.SpecialFolder.Personal,例如环境、特殊文件夹。CommonAppData@KlausGütter-我尝试了-相同的错误:当我直接从bin/debug运行exe时,找不到文件'C:\WINDOWS\system32\credentials.json。。。因此必须是任务计划程序中的一个设置