2

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.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
vicky
  • 241
  • 1
  • 3
  • 12

1 Answers1

0

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. enter image description here

Community
  • 1
  • 1
Noam Wies
  • 54
  • 4
  • yes, I already did it...i have a fixed port...and set the same port in google console redirect uri.... but even then it keeps on changing every time I test the app.. please suggest..what could be the reason for this ? – vicky Sep 17 '14 at 09:53
  • mשybe http://stackoverflow.com/questions/607562/visual-studio-development-server-using-wrong-port can help ? – Noam Wies Sep 17 '14 at 16:08