Uber request error

1.4k views Asked by At

I am using uber to book the cab in my application. I got price list and successfully authenticated to get Access token. After that i am trying to book the cab by using request API.

I included request scope.

This is my code to call request API:

private void bookUBER(String selectedProductId,String token,double startLatitude,double startLongitude,
            double endLatitude,double endLongitude) {

        UberAPIClient.getSandBox().getRequest(token, selectedProductId,
                startLatitude, startLongitude, endLatitude, endLongitude,
                new UberCallback<UberModel>() {
                    @Override
                    public void success(UberModel uberModel, Response response) {
                        super.success(uberModel, response);
                        Log.e("uberModel", uberModel.toString());
                        Log.e("response", "" + response);
                    }

                    @Override
                    public void failure(RetrofitError error) {
                        Log.e("bookUBER error ", "" + error);
                        super.failure(error);
                    }
                });

    }

Request method:

 @POST("/requests")
    void getRequest(@Header("Authorization") String authToken,
                    @Query("product_id") String productId,
                    @Query("start_latitude") double startLatitude,
                    @Query("start_longitude") double startLongitude,
                    @Query("end_latitude") double endLatitude,
                    @Query("end_longitude") double endLongitude,
                    Callback<UberModel> callback);

This is my logcat:

06-15 15:26:15.379: D/Retrofit(3142): <--- HTTP 406 https://sandbox-api.uber.com/v1/requests?product_id=fbc0033d-5a1a-4f01-964c-0e4ea56b6e7e&start_latitude=13.0497&start_longitude=80.2126&end_latitude=13.0827&end_longitude=80.2707 (2276ms)
06-15 15:26:15.379: D/Retrofit(3142): : HTTP/1.1 406 Not Acceptable
06-15 15:26:15.389: D/Retrofit(3142): Connection: keep-alive
06-15 15:26:15.389: D/Retrofit(3142): Content-Length: 164
06-15 15:26:15.389: D/Retrofit(3142): Content-Type: application/json
06-15 15:26:15.389: D/Retrofit(3142): Date: Mon, 15 Jun 2015 09:56:14 GMT
06-15 15:26:15.389: D/Retrofit(3142): Server: nginx
06-15 15:26:15.389: D/Retrofit(3142): Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
06-15 15:26:15.389: D/Retrofit(3142): X-Android-Received-Millis: 1434362175394
06-15 15:26:15.389: D/Retrofit(3142): X-Android-Sent-Millis: 1434362174535
06-15 15:26:15.389: D/Retrofit(3142): X-Uber-App: uberex-sandbox
06-15 15:26:15.389: D/Retrofit(3142): X-XSS-Protection: 1; mode=block
06-15 15:26:15.389: D/Retrofit(3142): {"message":"Only request header `Content-Type: application\/json` is supported for this endpoint. Please check your request headers.","code":"invalid_content_type"}
06-15 15:26:15.389: D/Retrofit(3142): <--- END HTTP (164-byte body)
06-15 15:26:15.399: E/bookUBER error(3142): retrofit.RetrofitError: 406 Not Acceptable
06-15 15:26:15.399: W/System.err(3142): retrofit.RetrofitError: 406 Not Acceptable
06-15 15:26:15.409: W/System.err(3142):     at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:388)
06-15 15:26:15.409: W/System.err(3142):     at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
06-15 15:26:15.409: W/System.err(3142):     at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
06-15 15:26:15.409: W/System.err(3142):     at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
06-15 15:26:15.409: W/System.err(3142):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-15 15:26:15.409: W/System.err(3142):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-15 15:26:15.409: W/System.err(3142):     at retrofit.Platform$Android$2$1.run(Platform.java:142)
06-15 15:26:15.409: W/System.err(3142):     at java.lang.Thread.run(Thread.java:856)

Am i miss anything?

Thanks in advance!

1

There are 1 answers

0
selva_pollachi On BEST ANSWER

Finally i got answer. Someone may get useful by this answer in future. I referred this.

I have changed request method:

@POST("/requests")
void getRequest(@Header("Authorization") String authToken,
                @Body HashMap<String, String> obj,
                Callback<UberModel> callback);

Method to call API:

private void bookUBER(String selectedProductId,String token,double startLatitude,double startLongitude,
            double endLatitude,double endLongitude) {

       HashMap<String, String> obj=new HashMap<String, String>();
            obj.put("product_id", selectedProductId);
            obj.put("start_latitude", String.valueOf(startLatitude));
            obj.put("start_longitude", String.valueOf(startLongitude));
            obj.put("end_latitude", String.valueOf(endLatitude));
            obj.put("end_longitude", String.valueOf(endLongitude));

            UberAPIClient.getSandBox().getRequest(token, obj,
                    new UberCallback<UberModel>() {
                        @Override
                        public void success(UberModel uberModel, Response response) {
                            super.success(uberModel, response);
                            Log.e("response", "" + response.toString());
                        }

                        @Override
                        public void failure(RetrofitError error) {
                            Log.e("uber price list error ", "" + error);
                            super.failure(error);
                        }
                    });

    }