我是学生,项目任务使用C#实现谷歌驱动器到网站。现在我在我的Visual Studio 2015中测试它。当我从我的VS启动网站时,它将启动一个验证的谷歌驱动器。我的身份验证成功,我可以将文件上传到云端硬盘但auth选项卡不会关闭。以下是我的代码。
Default.aspx.cs
using System;
using System.IO;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
var service = GoogleDriveHelper.AuthenticateOauth();
}
}
GoogleDriveHelper.cs
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
public class GoogleDriveHelper
{
public static DriveService AuthenticateOauth()
{
string[] scopes = new string[] { DriveService.Scope.Drive,
DriveService.Scope.DriveFile };
try
{
string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets {
ClientId = "My-client-id",
ClientSecret = "My-client-secret"
},
scopes,
"Users",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
DriveService service = new DriveService(new BaseClientService.Initializer() {
HttpClientInitializer = credential,
ApplicationName = "Google Drive API Demo",
});
return service;
}
catch
{
return null;
}
}
这是成功验证Google云端硬盘后我的身份验证标签。问题是,它在验证后没有关闭。
http://127.0.0.1:54972/authorize/?code=4/mbNAx__wjbnjsH6xJFtsgp3V6bDoweKrI8psJPaZd5E#
所以这是我试图解决的问题:
在IIS中部署此站点时出现另一个错误,身份验证失败。
错误:redirect_uri_mismatch
提前谢谢你们。