【问题标题】:Right credentials in requestBody for Android Google Play Oauth2 gtalk authTokenAndroid Google Play Oauth2 gtalk authToken 的 requestBody 中的正确凭据
【发布时间】:2013-04-18 13:30:58
【问题描述】:

运行下面的代码我得到“错误”:“unauthorized_client”。需要帮助查明我做错了什么。 我想在 Android 应用程序中使用它来启用 Google Talk(xmpp 已经存在 XABBER fork
阅读much 了解如何做到这一点,现在来Google Api Console setup
我选择了
- 已安装应用程序的客户端 ID
- 已安装的应用程序类型 = 其他
- 仅启用 Google Play Android Developer API(绿色开关)

我从 oauth2:https://www.googleapis.com/auth/googletalk 获取身份验证令牌。 (用户批准屏幕) 我没有输入“其他”的 SHA1 指纹或包名称,所以这可能是问题所在

代码:

     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();  
     }

【问题讨论】:

  • 我看过,其实你的问题是我的出发点。我只是忘记了一些东西,错字或重要的东西。仅启用 Google Play Android Developer API 的范围怎么样。

标签: android oauth-2.0 httpclient google-oauth


【解决方案1】:

我认为您应该使用“Android”类型注册您的应用程序。然后您将被要求提供信息(例如包名称和证书),以便 Android 平台识别您的应用程序。

【讨论】:

  • 是的,这可以部分工作,但如果我想从accounts.google.com/o/oauth2/token 获取 access_token 和 refresha_token 则不行
  • 是的,Android 平台确实按照您描述的方式识别了我的应用程序。测试票据样品,压延样品。上面的代码我确实获得了googleapis.com/auth/googletalk 的授权令牌,但是从该授权令牌中获取 access_token 和 refresha_token 是一堵墙。我知道 refresha_token 只是第一次发送。有什么想法吗?
  • 我想我不完全理解如何将您的答案与包名和证书一起使用,尤其是针对我的情况。你能说点什么吗?
  • 在 Android 上,您可以直接获得 access_token。您可以使用它来调用 API。您根本不需要使用 /o/oauth2/token 端点。
猜你喜欢
  • 2015-11-27
  • 2015-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-17
  • 2012-11-19
  • 2021-12-14
  • 2011-04-22
相关资源
最近更新 更多