[英]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.