Eri*_*ert 5 c# asp.net oauth google-api google-analytics-api
我有与这个问题完全相同的问题: 如何为GoogleWebAuthorizationBroker.AuthorizeAsync设置return_uri?
但是,这个问题在3年前就已经回答了,所提供的答案对我不起作用。我看不到实际设置重定向uri的方法。所以这是问题:
static async Task<UserCredential> GetCredential()
{
var clientSecretPath = HttpRuntime.AppDomainAppPath + "client_secret.json";
var credPath = HttpRuntime.AppDomainAppPath + "credentials/GoogleAnalyticsApiConsole/";
UserCredential credential;
using (var stream = new FileStream(clientSecretPath,
FileMode.Open, FileAccess.Read))
{
var secrets = GoogleClientSecrets.Load(stream).Secrets;
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
secrets,
new[] {AnalyticsReportingService.Scope.Analytics},
"analytics@mysite.com",
CancellationToken.None,
new FileDataStore(credPath, true));
return credential;
}
}
Run Code Online (Sandbox Code Playgroud)
这将返回以下错误:
failed to launch browser with https //accounts.google.com/o/oauth2/v2/auth
Run Code Online (Sandbox Code Playgroud)
它正在尝试使用redirect_uri =“ http:// localhost:/ authorize” 启动oauth2页面;当我尝试直接查看它尝试启动的URL时,页面上显示“请求中的重定向URI:http:// localhost:XXXXX / authorize /与注册的重定向URI不匹配”
我尝试仅将localhost:XXXXX添加到Google API控制台中的授权url中,但是下次运行该端口时,端口就不同了,例如localhost:XXXYY。我的client_secret.json文件列出了所有授权的重定向URL,但是没有被使用。如何设置重定向uri并解决此问题?
| 归档时间: |
|
| 查看次数: |
762 次 |
| 最近记录: |