Google+数据获取重定向uri不匹配

时间:2014-12-27 06:28:43

标签: android servlets google-api-java-client

我正在开发一个android应用程序以及在tomcat 7上运行的servlet Android应用程序允许用户通过谷歌登录,为此我使用谷歌oauth 2.0 登录后(在onConnected()中)我使用GoogleAuthUtil.getToken(...)来获取授权码(至少就是我认为的那样,如果错误则纠正我)

我将此代码传递给在http://localhost:8443/MyServlet/MyServ运行的servlet 在服务器上,我尝试为 access_token refresh_token 交换此授权码 但它总是给出

  

错误:redirect_uri_mismatch


下面是servlet代码

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://accounts.google.com/o/oauth2/token");
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("code", CODE)); 
pairs.add(new BasicNameValuePair("client_id", "MY_SERVER_CLENT_ID"));
pairs.add(new BasicNameValuePair("client_secret", "MY_SERVER_CLIENT_SECRET"));
pairs.add(new BasicNameValuePair("redirect_uri", "`https://localhost:8443/Myservlet/Myserv`"));   
pairs.add(new BasicNameValuePair("grant_type", "authorization_code"));
//Leave this line how it is 
post.setEntity(new UrlEncodedFormEntity(pairs));
org.apache.http.HttpResponse response2 = client.execute(post);
System.out.println("raw: " + response2.toString());
String responseBody = EntityUtils.toString(response2.getEntity());
System.out.println("message " + responseBody); // That just logs it into logCat

google console image

重定向uri已正确设置仍然出现此错误

任何形式的帮助将不胜感激

0 个答案:

没有答案