話說(shuō)遇到這個(gè)問(wèn)題真是比較坑爹括丁,微博的API還真有特點(diǎn)鸯檬。
報(bào)錯(cuò)信息:
error":"invalid_request","error_code":21323,"request":"/oauth2/access_token","error_uri":"/oauth2/access_token","error_description":"miss client id or secret“
解決方案:
參照文檔:http://open.weibo.com/wiki/OAuth2/access_token,這里寫(xiě)的是POST提交词渤,但是這里的post的URL為
https://api.weibo.com/oauth2/access_token?client_id=client_id&client_secret=client_secret&grant_type=authorization_code&code=code&redirect_uri=redirect_uri
提交的data應(yīng)該為空
參考代碼:
// 獲取access_token
String url = "https://api.weibo.com/oauth2/access_token?client_id=" + OtherConfig.WEIBO_APP_ID+ "&client_secret=" + OtherConfig.WEIBO_APP_SECRET+ "&grant_type=authorization_code&code="+code+"&redirect_uri="+OtherConfig.WEIBO_BACK_URI;
HttpPost httpPost = new HttpPost(url);
JSONObject json = new JSONObject();
String response = HttpClientUtils.doPost(httpPost, json.toJSONString());
成功解決牵舱,這里的data必須為空