Android版谷歌在requestBody权资格证书玩Oauth2的gtalk的authToken资格证书、requestBody、版谷歌、Android

2023-09-04 04:04:03 作者:不想起你就不会在乎自己曾经信以

运行code以下,我得到错误:unauthorized_client。需要帮助找出我做了什么错。 我想用这一个Android应用程序,使谷歌通话(XMPP是有已经 XABBER叉) 阅读有关如何做到这一点,现在来了的谷歌阿比控制台设置。 我选择 - 安装的应用程序客户端ID - 已安装的应用程序类型=其他 - 只启用了谷歌的Andr​​oid游戏开发者API(绿色开关)

我从oauth2认证令牌: https://www.googleapis.com/auth/googletalk 。 (用户认可画面) 什么错误我我不进入SHA1指纹或包名称为其他,所以也许这就是问题所在。

code:

  HttpClient的客户端1 =新DefaultHttpClient();
     HttpPost request1 =新HttpPost(https://accounts.google.com/o/oauth2/token);
     request1.setHeader(内容型,应用程序/ x-WWW的形式urlen codeD);

     //请让这个自定义的与您的凭据
     字符串requestBody1 =
            code =+的authToken +
            与&的client_id = 749825062016ia.apps.googleusercontent.com+
            与& client_secret = jQ1nUrAYUIBUf6hN5pwPE+
            &放大器; redirect_uri =金塔:IETF:WG:OAuth的:2.0:OOB+
            &放大器; grant_type = authorization_ code;

     尝试 {
         request1.setEntity(新StringEntity(requestBody1));
     }赶上(UnsupportedEncodingException E){
         e.printStackTrace();
     }

     / *检查响应* /
     尝试 {
         HTT presponse响应= client1.execute(request1);
         字符串结果=错误;
         结果= EntityUtils.toString(response.getEntity());
         LogManager.i(堆栈,回应::+结果);
     }赶上(IOException异常E){
         e.printStackTrace();
     }
 

解决方案

我想你应该已经注册的类型'Android的应用程序。然后,你将被要求提供的信息(如包名称和证书),使Android平台认识到你的应用程序。

Running the code below I get "error" : "unauthorized_client". Need help pinpoint what I have done wrong. I Want to use this in an Android app to enable Google Talk (xmpp is there already XABBER fork) Reading much about how to do this and now come the Google Api Console setup. I have chosen - Client ID for installed applications - Installed application type = Other - Enabled only the Google Play Android Developer API (green switch)

I get the authentication token from oauth2:https://www.googleapis.com/auth/googletalk. (user approval screen) What bugs me I dont enter the SHA1 fingerprint or package name for "Other" so maybe that's the problem

code:

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

     //Please make this custom with you're credentials
     String requestBody1 = 
            "code="+authToken+
            "&client_id=749825062016ia.apps.googleusercontent.com"+      
            "&client_secret=jQ1nUrAYUIBUf6hN5pwPE" +
            "&redirect_uri=urn:ietf:wg:oauth:2.0:oob" +
            "&grant_type=authorization_code";

     try {
         request1.setEntity(new StringEntity(requestBody1));
     } catch (UnsupportedEncodingException e) {
         e.printStackTrace();
     }

     /* Checking response */
     try {
         HttpResponse response = client1.execute(request1);
         String results = "ERROR";
         results = EntityUtils.toString(response.getEntity());
         LogManager.i("STACK", "Response::" + results);
     } catch (IOException e) {
         e.printStackTrace();  
     }

解决方案

I think you should have registered your application with type 'Android'. Then you will be asked to provide information (such as package name and certificate) that will allow the Android platform to recognize your application.