[英]Right credentials in requestBody for Android Google Play Oauth2 gtalk authToken
运行下面的代码,我得到“错误”:“ unauthorized_client”。 需要帮助找出我做错了什么。 我想在Android应用中使用它来启用Google Talk(xmpp已经存在XABBER fork )
读太多有关如何做到这一点,现在来到了谷歌API控制台中设置 。
我已经选择
-已安装应用程序的客户端ID
-已安装的应用程序类型=其他
-仅启用了Google Play Android开发者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();
}
我认为您应该已经使用“ Android”类型注册了您的应用程序。 然后,系统将要求您提供信息(例如程序包名称和证书),以使Android平台能够识别您的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.