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.