[英]Confusion with redirect_uri in OAuth 2.0
我一直在使用谷歌Analytics(分析)为我的网站,我已经在weebly创建 。 我正在使用Google API以编程方式实现整个过程。
我在OAuth流程中遇到的问题是我收到此错误:
Error: redirect_uri_mismatch
The redirect URI in the request:localhost:34190/Callback did not match a registered redirect URI
Request Details
scope=https://www.googleapis.com/auth/analytics.readonly
response_type=code
access_type=online
redirect_uri=local_host:34190/Callback
display=page
client_id={CLIENT_ID}.apps.googleusercontent.com
我的谷歌api控制台配置是:
Redirect URI: localhost/oauth2callback
JavaScript origins: localhost
为什么在地球上redirect_uri
是localhost:34190/Callback
当我设置为: http://mya.com/oauth2callback
: http://mya.com/oauth2callback
?
我为openauth写的代码:
public static void main(String[] args) throws Exception {
Analytics analytics = initializeAnalytics();
}
private static Analytics initializeAnalytics() throws Exception {
Credential credential = authorize();
}
private static Credential authorize() throws Exception {
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
JSON_FACTORY, Testcode.class.getResourceAsStream("/client_secrets.json"));
FileCredentialStore credentialStore = new FileCredentialStore(
new File(System.getProperty("user.home"), ".credentials/analytics.json"),
JSON_FACTORY);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets,
Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY)).setCredentialStore(
credentialStore).build();
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver())
.authorize(clientSecrets.getDetails().getClientId());
}
我怎样才能摆脱这个错误?
所以你的网站告诉谷歌使用localhost:34190/Callback
作为重定向URI。 但是您已经对Google服务器说过,当您的应用将localhost/oauth2callback
指定为重定向URI时,他只应接受请求。
简单的解决方法是按如下方式设置Google控制台:
Redirect URI: http://localhost:34190/Callback
无论如何,你在谈论你想要重定向到http://mya.com/oauth2callback
。
在这种情况下,您应该更改用户在您网站上点击的链接以指定此链接
[...]&redirect_uri=http://mya.com/oauth2callback[...]
然后在Google控制台中进行设置:
Redirect URI: http://mya.com/oauth2callback
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.