简体   繁体   English

适用于Android Google Play Oauth2 gtalk authToken的requestBody中的正确凭据

[英]Right credentials in requestBody for Android Google Play Oauth2 gtalk authToken

Running the code below I get "error" : "unauthorized_client". 运行下面的代码,我得到“错误”:“ 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 ) 我想在Android应用中使用它来启用Google Talk(xmpp已经存在XABBER fork
Reading much about how to do this and now come the Google Api Console setup . 太多有关如何做到这一点,现在来到了谷歌API控制台中设置
I have chosen 我已经选择
- Client ID for installed applications -已安装应用程序的客户端ID
- Installed application type = Other -已安装的应用程序类型=其他
- Enabled only the Google Play Android Developer API (green switch) -仅启用了Google Play Android开发者API(绿色开关)

I get the authentication token from oauth2: https://www.googleapis.com/auth/googletalk . 我从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 (用户批准屏幕)我不满意的地方我没有为“其他”输入SHA1指纹或软件包名称,所以可能是问题所在

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'. 我认为您应该已经使用“ 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. 然后,系统将要求您提供信息(例如程序包名称和证书),以使Android平台能够识别您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM