我创建了一个抓取应用程序(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);
}
我有一个certificate.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
然后我将凭据.json复制到C:\ WINDOWS \ system32 \,但是仍然出现错误。
答案 0 :(得分:0)
在操作中,将可选的启动更改为文件夹路径。 操作>编辑>程序/脚本= YOurGoogle.exe>从(可选)开始>例如C:\ Users \ Me \