【发布时间】: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