谷歌Auth2给予&QUOT

谷歌Auth2给予&QUOT

本文介绍了谷歌Auth2给予" INVALID_REQUEST"响应获得访问令牌和放大器;刷新令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

如何获得访问令牌和放大器;刷新令牌的XMPP谷歌认证。我得到成功授权code,但现在我需要获得访问令牌和放大器;刷新令牌。但是,当我做请求的Andr​​oid与下面code我得到的回应:{  错误:INVALID_REQUEST}

How to get the access token & refresh token for google authentication for XMPP. I get successfully the authorization code, but now I need to get the access token & refresh token. But when I do the request in Android with the underneath code I get the response:{ "error":"invalid_request"}

HttpPost request = new HttpPost("https://accounts.google.com/o/oauth2/token" );
json.put("client_id", "128232338269.apps.googleusercontent.com" );
json.put("client_secret", "eufZ8Rmjsk1MaADYsHYW" );
json.put("redirect_uri", "urn:ieadsdg:oauth:2.0:oob");
json.put("code", res_code);
json.put("grant_type", "authorization_code");

StringEntity se = new StringEntity(json.toString());

Log.i(TAG, "JSON********" +json.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
request.setEntity(se);

/* Checking response */
response = client.execute(request);

但我得到这个错误为code。 响应= {    错误:INVALID_REQUEST }

but i am getting this error for that code. Response = { "error" : "invalid_request" }

有什么问题就在这里。 HttpPost方法是正确的这个网址。

what is the problem here. HttpPost method is the correct for this url.

推荐答案

聊天后,我们发现有什么问题的地方。有效载荷的错误,所述内容类型设置错。下面code是解决方案:

After a chat we found what the problems where. The payload wrong and the content-type was set wrong. The following code is the solution:

    HttpClient client = new DefaultHttpClient();
    HttpPost request = new HttpPost("https://accounts.google.com/o/oauth2/token" );
    request.setHeader("Content-type", "application/x-www-form-urlencoded");

    //Please make this custom with you're credentials
    String requestBody = "code=123123132&client_secret=eufFgyAZ8Rmjsk1MaADYsHYW&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code&client_id=128169428269.apps.googleusercontent.com";

    try {
        request.setEntity(new StringEntity(requestBody));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }

    /* Checking response */
    try {
        HttpResponse response = client.execute(request);
        String results = "ERROR";
        results = EntityUtils.toString(response.getEntity());
        Log.d("STACK", "Response::" + results);
    } catch (IOException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }

这篇关于谷歌Auth2给予" INVALID_REQUEST"响应获得访问令牌和放大器;刷新令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:42