【问题标题】:Rediret Uri changes automatically重定向 Uri 自动更改
【发布时间】: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


    【解决方案1】:

    您需要为 ASP.NET 开发服务器指定一个修复端口,例如 How to fix a port number in asp.NET development server,并将这个带有修复端口的 url 添加到允许的 url。

    【讨论】:

    • 是的,我已经做到了...我有一个固定的端口...并在 google 控制台重定向 uri 中设置了相同的端口...但即使这样,每次我测试时它都会不断变化该应用程序..请建议..这可能是什么原因?
    • mשybe stackoverflow.com/questions/607562/… 可以帮忙吗?
    猜你喜欢
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    • 1970-01-01
    相关资源
    最近更新 更多