【发布时间】:2021-11-13 10:40:05
【问题描述】:
我正在尝试将 google drive api 与我在 http://127.0.0.1:4000 上运行的 asp.net core 3.1 Web 服务器连接。但在授权期间我得到不同的 redirect_uri。并且 credential.json 都是有效的。
我得到的错误:
我的代码:
public class GDriveService : BaseService
{
private string credentialFileName = ConfigurationManager.AppSettings["CredentialFile"].ToString();
private string appName = ConfigurationManager.AppSettings["AppName"].ToString();
private string[] scopes;
private UserCredential credential;
private DriveService service;
public GDriveService(IWebHostEnvironment env):base(env)
{
scopes = new string[] { DriveService.Scope.Drive,
DriveService.Scope.DriveFile,};
using (var stream = new FileStream(Path.Combine(env.WebRootPath, credentialFileName), FileMode.Open, FileAccess.Read))
{
String FilePath = Path.Combine(env.WebRootPath, "DriveServiceCredentials");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user",
CancellationToken.None,
new FileDataStore(FilePath, true)).Result;
}
}
我的凭据配置:
【问题讨论】:
-
您是否已提交 OAuth2 屏幕配置以供验证?
-
我也遇到了这个问题。 @ziganotschka 我在谷歌控制台中的应用程序仍处于测试阶段,我已经提交了 OAuth2 同意屏幕。不过,它似乎不起作用。帮忙?
-
我在 GCP 中使用
http://localhost/authorize/作为重定向 URL,从 Visual Studio 运行 Web 应用程序。然后我尝试连接到 Google Drive API 并失败了几次。然后我刷新我的 Web 应用程序(仍然连接调试器)并等待几分钟,然后再试一次。令我惊讶的是,它起作用了,但只是暂时的。奇怪..
标签: asp.net .net-core oauth-2.0 google-drive-api google-api-dotnet-client