【发布时间】:2014-11-11 02:28:35
【问题描述】:
我正在使用以下代码将谷歌驱动器与我的 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/
但每次我尝试使用提示登录时都会收到错误消息:
400 这是一个错误。 错误:redirect_uri_mismatch 请求中的重定向 URI:
http://localhost:50804/authorize/与注册的重定向 URI 不匹配。
请注意这里的端口号每次都会自动更改,无论我更改多少次。它没有获取我在应用程序控制台中提到的重定向 uri。
【问题讨论】:
标签: c# asp.net google-api-dotnet-client google-drive-api