优步请求错误

时间:2015-06-15 10:20:38

标签: android retrofit uber-api

我正在使用uber在我的应用程序中预订出租车。我获得了价格表并成功通过身份验证以获取Access令牌。之后,我尝试使用request API预订出租车。

我加入了request scope

这是我调用请求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);
                    }
                });

    }

请求方法:

 @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);

这是我的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)

我错过了什么吗?

提前致谢!

1 个答案:

答案 0 :(得分:0)

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);
                        }
                    });

    }
相关问题