400调用Sinch REST API时出错

时间:2017-03-08 15:33:46

标签: android rest sinch android-sinch-api

我正在使用Sinch在Android中创建一个应用程序,我需要的一些功能只能通过调用他们的REST API来实现。我想静默一个特定的用户,因为我已经编写了这样的代码

        String userName = call.getCallId();
        final String muteURL = URL+CallingUsersName+"/"+userName;
        final String muteParticipant = "{ \"command\" : \"mute\" }";
        JSONObject muteJSON;
        try{
            muteJSON = new JSONObject(muteParticipant);
            Toast.makeText(getActivity(),muteJSON.toString(),Toast.LENGTH_SHORT).show();
        }catch (JSONException e ) {
            muteJSON = null;
            Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_SHORT).show();
        }
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.PATCH, muteURL, muteJSON, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                mConferenceParticipants.setText(response.toString());

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mConferenceParticipants.setText(error.toString());

            }
        }){
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> params = new HashMap<String, String>();
                String creds = String.format("%s:%s",AppKey,AppSecretKey);
                String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.NO_WRAP);
                params.put("Authorization", auth);
                params.put("Content-Type", "application/json");
//                params.put("X-HTTP-Method-Override", "PATCH");
                return params;
//                return super.getHeaders();
            }
        };
//        jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(8000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        rq.add(jsonObjectRequest);

当我调用此请求时,会议实际上正在进行,但我收到此错误

BasicNetwork.performRequest: Unexpected response code 400 for https://callingapi.sinch.com/v1/conferences/id/Meeting/a291ba94-e430-454f-80a9-73013cd43451

我认为400意味着会议未找到,但会议已经建立,在同一活动中,我也称REST API会告诉我不。会议的参与者,这是正常的。

知道这有什么问题吗?

2 个答案:

答案 0 :(得分:1)

我试图解决这个问题很长一段时间,最后让它运转起来。这是代码:

  public void MuteTheParticipants(){
        String userName = call.getCallId();
        final String muteURL = URL+CallingUsersName+"/"+userName;
        StringRequest sr = new StringRequest(Request.Method.PATCH, muteURL, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                if(flag)
                    muteButton.setBackgroundResource(R.drawable.microphone);
                else
                    muteButton.setBackgroundResource(R.drawable.microphone_off
                    );

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(getActivity(),error.toString(),Toast.LENGTH_SHORT).show();
            }
        }){
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> params = new HashMap<String, String>();
                String creds = String.format("%s:%s",AppKey,AppSecretKey);
                String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.NO_WRAP);
                params.put("Authorization", auth);
                return params;
//                return super.getHeaders();
            }

            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> params = new HashMap<String, String>();
                if(!flag) {
                    params.put("command", "mute");
                    flag = true;
                }else {
                    params.put("command", "unmute");
                    flag = false;
                }
                return params;
            }
        };
        sr.setRetryPolicy(new DefaultRetryPolicy(8000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        rq.add(sr);
}

答案 1 :(得分:0)

你的变量显示用户名,它应该是callid你静音而不是用户名