Why is my google account authentication failing?












0















I have created a scraping application ( C# ) that writes results to a private Google Sheet.



When I run the application in Debug mode, it works as expected and authenticates.
However, when I run it as a task, the authentication fails here...



 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);
}


I have a credentials.json file set to copy always in the project and it is being copied to the bin/debug and bin/release folders on compilation.



The error I am getting (only when run in task scheduler) is this....



Unhandled Exception: System.IO.FileNotFoundException: Could not find file 
'C:WINDOWSsystem32credentials.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:UsersxxxDocumentsVisual Studio
2017ProjectsScreenScraperScreenScraperProgram.cs:line 74
at ScreenScraper.Program.Main(String args) in C:UsersxxxDocumentsVisual
Studio 2017ProjectsScreenScraperScreenScraperProgram.cs:line 38




I then copied credentials.json to C:WINDOWSsystem32 but I am still getting the error.










share|improve this question

























  • Permission issue perhaps?

    – just-my-name
    Nov 21 '18 at 19:39











  • Possibly - I gave full read permission to the folder - same error

    – Greg
    Nov 21 '18 at 19:45











  • I suggest you choode a different path tham Environment.SpecialFolder.Personal, e.g. Environment.SpecialFolder.CommonAppData

    – Klaus Gütter
    Nov 21 '18 at 19:47











  • @KlausGütter - I tried that - same error : Could not find file 'C:WINDOWSsystem32credentials.json

    – Greg
    Nov 21 '18 at 19:52











  • When I run the exe directly from the bin/debug it works ... so must be a setting in the task scheduler

    – Greg
    Nov 21 '18 at 19:57
















0















I have created a scraping application ( C# ) that writes results to a private Google Sheet.



When I run the application in Debug mode, it works as expected and authenticates.
However, when I run it as a task, the authentication fails here...



 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);
}


I have a credentials.json file set to copy always in the project and it is being copied to the bin/debug and bin/release folders on compilation.



The error I am getting (only when run in task scheduler) is this....



Unhandled Exception: System.IO.FileNotFoundException: Could not find file 
'C:WINDOWSsystem32credentials.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:UsersxxxDocumentsVisual Studio
2017ProjectsScreenScraperScreenScraperProgram.cs:line 74
at ScreenScraper.Program.Main(String args) in C:UsersxxxDocumentsVisual
Studio 2017ProjectsScreenScraperScreenScraperProgram.cs:line 38




I then copied credentials.json to C:WINDOWSsystem32 but I am still getting the error.










share|improve this question

























  • Permission issue perhaps?

    – just-my-name
    Nov 21 '18 at 19:39











  • Possibly - I gave full read permission to the folder - same error

    – Greg
    Nov 21 '18 at 19:45











  • I suggest you choode a different path tham Environment.SpecialFolder.Personal, e.g. Environment.SpecialFolder.CommonAppData

    – Klaus Gütter
    Nov 21 '18 at 19:47











  • @KlausGütter - I tried that - same error : Could not find file 'C:WINDOWSsystem32credentials.json

    – Greg
    Nov 21 '18 at 19:52











  • When I run the exe directly from the bin/debug it works ... so must be a setting in the task scheduler

    – Greg
    Nov 21 '18 at 19:57














0












0








0








I have created a scraping application ( C# ) that writes results to a private Google Sheet.



When I run the application in Debug mode, it works as expected and authenticates.
However, when I run it as a task, the authentication fails here...



 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);
}


I have a credentials.json file set to copy always in the project and it is being copied to the bin/debug and bin/release folders on compilation.



The error I am getting (only when run in task scheduler) is this....



Unhandled Exception: System.IO.FileNotFoundException: Could not find file 
'C:WINDOWSsystem32credentials.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:UsersxxxDocumentsVisual Studio
2017ProjectsScreenScraperScreenScraperProgram.cs:line 74
at ScreenScraper.Program.Main(String args) in C:UsersxxxDocumentsVisual
Studio 2017ProjectsScreenScraperScreenScraperProgram.cs:line 38




I then copied credentials.json to C:WINDOWSsystem32 but I am still getting the error.










share|improve this question
















I have created a scraping application ( C# ) that writes results to a private Google Sheet.



When I run the application in Debug mode, it works as expected and authenticates.
However, when I run it as a task, the authentication fails here...



 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);
}


I have a credentials.json file set to copy always in the project and it is being copied to the bin/debug and bin/release folders on compilation.



The error I am getting (only when run in task scheduler) is this....



Unhandled Exception: System.IO.FileNotFoundException: Could not find file 
'C:WINDOWSsystem32credentials.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:UsersxxxDocumentsVisual Studio
2017ProjectsScreenScraperScreenScraperProgram.cs:line 74
at ScreenScraper.Program.Main(String args) in C:UsersxxxDocumentsVisual
Studio 2017ProjectsScreenScraperScreenScraperProgram.cs:line 38




I then copied credentials.json to C:WINDOWSsystem32 but I am still getting the error.







c# .net google-sheets google-authentication google-api-dotnet-client






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 21:10









TheMaster

9,9953732




9,9953732










asked Nov 21 '18 at 19:36









GregGreg

1,72832644




1,72832644













  • Permission issue perhaps?

    – just-my-name
    Nov 21 '18 at 19:39











  • Possibly - I gave full read permission to the folder - same error

    – Greg
    Nov 21 '18 at 19:45











  • I suggest you choode a different path tham Environment.SpecialFolder.Personal, e.g. Environment.SpecialFolder.CommonAppData

    – Klaus Gütter
    Nov 21 '18 at 19:47











  • @KlausGütter - I tried that - same error : Could not find file 'C:WINDOWSsystem32credentials.json

    – Greg
    Nov 21 '18 at 19:52











  • When I run the exe directly from the bin/debug it works ... so must be a setting in the task scheduler

    – Greg
    Nov 21 '18 at 19:57



















  • Permission issue perhaps?

    – just-my-name
    Nov 21 '18 at 19:39











  • Possibly - I gave full read permission to the folder - same error

    – Greg
    Nov 21 '18 at 19:45











  • I suggest you choode a different path tham Environment.SpecialFolder.Personal, e.g. Environment.SpecialFolder.CommonAppData

    – Klaus Gütter
    Nov 21 '18 at 19:47











  • @KlausGütter - I tried that - same error : Could not find file 'C:WINDOWSsystem32credentials.json

    – Greg
    Nov 21 '18 at 19:52











  • When I run the exe directly from the bin/debug it works ... so must be a setting in the task scheduler

    – Greg
    Nov 21 '18 at 19:57

















Permission issue perhaps?

– just-my-name
Nov 21 '18 at 19:39





Permission issue perhaps?

– just-my-name
Nov 21 '18 at 19:39













Possibly - I gave full read permission to the folder - same error

– Greg
Nov 21 '18 at 19:45





Possibly - I gave full read permission to the folder - same error

– Greg
Nov 21 '18 at 19:45













I suggest you choode a different path tham Environment.SpecialFolder.Personal, e.g. Environment.SpecialFolder.CommonAppData

– Klaus Gütter
Nov 21 '18 at 19:47





I suggest you choode a different path tham Environment.SpecialFolder.Personal, e.g. Environment.SpecialFolder.CommonAppData

– Klaus Gütter
Nov 21 '18 at 19:47













@KlausGütter - I tried that - same error : Could not find file 'C:WINDOWSsystem32credentials.json

– Greg
Nov 21 '18 at 19:52





@KlausGütter - I tried that - same error : Could not find file 'C:WINDOWSsystem32credentials.json

– Greg
Nov 21 '18 at 19:52













When I run the exe directly from the bin/debug it works ... so must be a setting in the task scheduler

– Greg
Nov 21 '18 at 19:57





When I run the exe directly from the bin/debug it works ... so must be a setting in the task scheduler

– Greg
Nov 21 '18 at 19:57












1 Answer
1






active

oldest

votes


















0














In actions change optional start up to the folder path.
Actions > Edit > Program/script = YOurGoogle.exe > Start in (Optional) > eg.C:UsersMe






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419389%2fwhy-is-my-google-account-authentication-failing%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    In actions change optional start up to the folder path.
    Actions > Edit > Program/script = YOurGoogle.exe > Start in (Optional) > eg.C:UsersMe






    share|improve this answer




























      0














      In actions change optional start up to the folder path.
      Actions > Edit > Program/script = YOurGoogle.exe > Start in (Optional) > eg.C:UsersMe






      share|improve this answer


























        0












        0








        0







        In actions change optional start up to the folder path.
        Actions > Edit > Program/script = YOurGoogle.exe > Start in (Optional) > eg.C:UsersMe






        share|improve this answer













        In actions change optional start up to the folder path.
        Actions > Edit > Program/script = YOurGoogle.exe > Start in (Optional) > eg.C:UsersMe







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 23:46









        Josh CraigJosh Craig

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419389%2fwhy-is-my-google-account-authentication-failing%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Ottavio Pratesi

            Tricia Helfer

            15 giugno