授权错误错误400:Google驱动器api中的redirect_uri_mismatch

时间:2020-11-09 10:22:18

标签: asp.net-core asp.net-core-webapi

授权错误 错误400:redirect_uri_mismatch 请求http://127.0.0.1:57916/authorize/中的重定向URI与为OAuth客户端授权的重定向URI不匹配。要更新授权的重定向URI,请访问:https://console.developers.google.com/apis/credentials/oauthclient/${your_client_id}?project=${your_project_number}

我们每次都会收到授权错误。当我们在本地主机上运行google drive网站的intregation代码时,在google开发者控制台帐户中进行所有配置后,它将给出错误400:redirect_uri_mismatch。响应。

我已经在Application Type桌面上尝试过它,它可以在本地计算机上运行,​​但不能在服务器上运行。当我尝试过“应用程序类型Web”时,它也不适用于本地。

请提供帮助。

enter image description here

public static Google.Apis.Drive.v3.DriveService GetService(string path)
        {
            UserCredential credential;
            try
            {
                //getPath = IHostingEnvironment .ContentRootPath + "\\Content\\";
                //get Credentials from client_secret.json file 
               
                string FolderPath = path;
                //var CSPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/");
                string[] Scopes = new string[] { DriveService.Scope.Drive };
                using (var stream = new FileStream(Path.Combine(path, "shaApplication.json"), FileMode.Open, FileAccess.Read))
                {
                    //String FolderPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/"); ;
                    String FilePath = Path.Combine(FolderPath, "DriveServiceCredentials.json");
                    //dsAuthorizationBroker.RedirectUri = "http://localhost:58196";

                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(FilePath, true)).Result;

                }
            }
            catch(Exception ex)
            {
                throw new Exception(""+ex);
            }
            //create Drive API service.
            Google.Apis.Drive.v3.DriveService service = new Google.Apis.Drive.v3.DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "Web SHA Client",
            });
            return service;
        }

0 个答案:

没有答案