Google Drive API upload Fails after hosting it to IIS. showing the error as Failed to launch the Browser with

后端 未结 1 2024
悲哀的现实
悲哀的现实 2021-01-27 02:35

I am using google external login in my application, and I need a functionality that user can upload images from the application to his google drive.

In my localhost code

1条回答
  •  孤独总比滥情好
    2021-01-27 02:36

    You are using GoogleWebAuthorizationBroker.AuthorizeAsync which is designed for use with installed applications. It spanws the web browser on the machine that it runs on. This will work fine when you are working locally but it will fail when you try to run it on a server as you dont have access to spawn a browser on the server (not that it would help as the user will not see it)

    what you should be using is something like this

    private static readonly IAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
                {
                    ClientSecrets = new ClientSecrets
                    {
                        ClientId = "PUT_CLIENT_ID_HERE",
                        ClientSecret = "PUT_CLIENT_SECRET_HERE"
                    },
                    Scopes = new[] { DriveService.Scope.Drive },
                    DataStore = new FileDataStore("Drive.Api.Auth.Store")
                });
    

    A full example can be found here Web applications (ASP.NET MVC)

    0 讨论(0)
提交回复
热议问题