Rediret Uri会自动更改 [英] Rediret Uri changes automatically
问题描述
protected void Button1_Click(object sender,EventArgs)使用下面的代码将Google Drive与我的C#示例进行整合: e)
{
UserCredential凭证= GoogleWebAuthorizationBroker.AuthorizeAsync(
新ClientSecrets
{
ClientId =************** ******,
ClientSecret =********************
},
new [] { DriveService.Scope.DriveFile},
user,
CancellationToken.None).Result;
//创建服务。
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer =凭证,
ApplicationName =Drive API Sample,
});
File body = new File();
body.Title =我的文档;
body.Description =测试文档;
body.MimeType =image / jpeg;
string path =;
byte [] byteArray = System.IO.File.ReadAllBytes(D:\\babita_backup\\Babita\\GoogledriveIntegration\\Koala.jpg);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
尝试
{
FilesResource.InsertMediaUpload request = service.Files.Insert(body,stream,image / jpeg);
request.Upload();
File file = request.ResponseBody;
// Label1.Text = file.Id;
catch {}
}
我有:
redirect uri为:
https:// localhost:50027 / GoogleAPI / callback.aspx
javascript起源为:
https:// localhost:50027 /
但每当我尝试使用promt登录时我收到错误消息:
<400>这是一个错误。
错误:redirect_uri_mismatch
请求中的重定向URI:http:// localhost:50804 / authorize /
与注册的重定向URI不匹配。
请注意,这里端口号每次都会自动改变,无论我改变了多少次。它不包含我在应用程序控制台中提到的重定向uri。
您需要为ASP指定一个修复端口.NET开发服务器,如如何修复一个端口在asp.net开发服务器中输入数字并将此URL与修复端口一起添加到允许的URL中。
I am using the below code to integrate google drive with my C# example:
protected void Button1_Click(object sender, EventArgs e)
{
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "********************",
ClientSecret = "********************"
},
new[] { DriveService.Scope.DriveFile },
"user",
CancellationToken.None).Result;
// Create the service.
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Drive API Sample",
});
File body = new File();
body.Title = "My document";
body.Description = "A test document";
body.MimeType = "image/jpeg";
string path = "";
byte[] byteArray = System.IO.File.ReadAllBytes("D:\\babita_backup\\Babita\\GoogledriveIntegration\\Koala.jpg");
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
try
{
FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "image/jpeg");
request.Upload();
File file = request.ResponseBody;
// Label1.Text = file.Id;
}
catch { }
}
And I have: redirect uri as:
https://localhost:50027/GoogleAPI/callback.aspx
javascript origins as:
https://localhost:50027/
But every time when I try to login with the promt I am getting the error:
400 That’s an error. Error: redirect_uri_mismatch The redirect URI in the request:
http://localhost:50804/authorize/
did not match a registered redirect URI.
Please note that here the port number changes automatically every time, no matter how many times I change it. Its not picking up the redirect uri that I mentioned in the app console.
you need to specify a fix port for the ASP.NET development server like How to fix a port number in asp.NET development server and add this url with the fix port to the allowed urls.
这篇关于Rediret Uri会自动更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!