1
我一直在使用Google Analytics作爲我的網站,我有created in weebly。我正在使用Google API以編程方式實現整個事情。OAuth 2.0中redirect_uri的混淆
我的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
?這都是我爲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());
}
我怎樣才能擺脫這種錯誤的?
感謝揚!!!!,我將google api控制檯設置爲localhost:34190,但它每次都在更改,甚至mya.com在我的主機文件中解析爲本地主機。 – rampuriyaaa 2013-03-26 12:12:20
如果我的答案確實有幫助,那麼將其標記爲*接受*會很好。 – 2013-03-26 14:16:00
Hey Jan !!!! ...你發佈的信息我已經知道了,我從其他網站上找到了。我的問題仍然沒有解決 – rampuriyaaa 2013-03-27 03:33:12