我使用以下代码将google驱动器与我的C#示例集成:
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 { }
}
我有: 将uri重定向为:
https://localhost:50027/GoogleAPI/callback.aspx
javascript起源于:
https://localhost:50027/
但每当我尝试使用promt登录时,我都会收到错误:
400那是一个错误。 错误:redirect_uri_mismatch 请求中的重定向URI:
http://localhost:50804/authorize/
与已注册的重定向URI不匹配。
请注意,此处端口号每次都会自动更改,无论我更改多少次。它没有拿起我在app控制台中提到的重定向uri。
答案 0 :(得分:0)
您需要为ASP.NET开发服务器指定一个修复端口,如How to fix a port number in asp.NET development server,并将此url与修复端口一起添加到允许的URL。