希望你们做的很好。 我正在从事一项活动,该活动需要从API中解析一些值,而该API需要具有一些参数的POST请求。 我已经尽了我所能理解的一切来弄错了,但是我没有什么错,因为它使我除了错误以外没有其他回报。任何帮助将不胜感激。
链接到API文档(1)-https://followiz.com/api
链接到API文档(2)-https://www.greatsmm.in/api_docs
我正在解析 BALANCE ,请在上述两个链接的底部找到它。
这是我正在使用的方法-
private void Balance() {
String url="https://followiz.com/api/v2";
//here you can choose your method,GET/POST,in this case is Post
JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.POST,
url , null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("Volley response","Response is "+response);
try {
Toast.makeText(SMM.this, "The balance is "+response.getInt("balance"), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
Log.e("Exp","The error is "+e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Main Error","The error is "+error);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
//send your parameter here
Map<String, String> parameters = new HashMap<>();
parameters.put("key", "api_key(deleted because of sec. reasons)");
parameters.put("action", "balance");
return parameters;
}
//adding header to authenticate
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
return headers;
}
};
mQueue.add(jsonReq);
}
我遇到的错误是-
Response is {"error":"Incorrect request"}
The error is org.json.JSONException: No value for balance