简体   繁体   中英

Right credentials in requestBody for Android Google Play Oauth2 gtalk authToken

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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