gpt4 book ai didi

c# - 获取 .NET Google API RefreshToken - 访问被拒绝

转载 作者:行者123 更新时间:2023-11-30 18:20:46 26 4
gpt4 key购买 nike

我尝试使用此代码通过 Google.Apis.Auth.OAuth2 库获取应用程序的 Google 刷新 token 。当我在 localhost 上使用它时,它工作完美,但是当我在 Azure 站点下使用它时,它将抛出 System.AggregateException访问被拒绝 InnerException。

UserCredential credential =
GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets()
{
ClientId = "<client_id>",
ClientSecret = "<client_secret>"
},
new string[] { },
Environment.UserName,
CancellationToken.None,
null
).Result;

string refreshToken = credential.Token.RefreshToken;

内部异常是:

InnerException Message: Access is denied at System.Net.HttpListener.SetupV2Config() at System.Net.HttpListener.Start() at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext()

还有其他方式获取刷新 token 吗?

谢谢!

最佳答案

您是否已将 Azure URI 配置为在 Google 控制台 API 管理器中授权?

关于c# - 获取 .NET Google API RefreshToken - 访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36917276/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com