优步api返回null

时间:2017-09-16 15:18:58

标签: android uber-api

我正在尝试在我的Android应用中显示uber的票价估算值,使用改装从api加载数据,我甚至收到状态码= 200(这应该是uber的docs) ,但无论我选择哪种坐标,我的价格表总是空的。

**retrofit interface class.**

    public interface PriceEstimate {

    @GET("/v1.2/estimates/price")
    Call<Prices> getEstimate(@Header("Authorization") String authToken,
                                 @Query("start_latitude") float start_latitude,
                                 @Query("start_longitude") float start_longitude,
                                 @Query("end_latitude") float stop_latitude,
                                 @Query("end_longitude") float stop_longitude);
}

价格等级:

public class Prices {
    public List<PriceModel> prices;
    private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public List<PriceModel> getPrices() {
    return prices;
}

public void setPrices(List<PriceModel> prices) {
    this.prices = prices;
}

public Map<String, Object> getAdditionalProperties() {
    return this.additionalProperties;
}

public void setAdditionalProperty(String name, Object value) {
    this.additionalProperties.put(name, value);
}

}

价格模型:

 public class PriceModel {

    private String localizedDisplayName;
    private Double distance;
    private String displayName;
    private String productId;
    private Object highEstimate;
    private Object lowEstimate;
    private Integer duration;
    private String estimate;
    private Object currencyCode;
    private Map<String, Object> additionalProperties = new HashMap<String, Object>();

    public String getLocalizedDisplayName() {
        return localizedDisplayName;
    }

    public void setLocalizedDisplayName(String localizedDisplayName) {
        this.localizedDisplayName = localizedDisplayName;
    }

    public Double getDistance() {
        return distance;
    }

    public void setDistance(Double distance) {
        this.distance = distance;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public Object getHighEstimate() {
        return highEstimate;
    }

    public void setHighEstimate(Object highEstimate) {
        this.highEstimate = highEstimate;
    }

    public Object getLowEstimate() {
        return lowEstimate;
    }

    public void setLowEstimate(Object lowEstimate) {
        this.lowEstimate = lowEstimate;
    }

    public Integer getDuration() {
        return duration;
    }

    public void setDuration(Integer duration) {
        this.duration = duration;
    }

    public String getEstimate() {
        return estimate;
    }

    public void setEstimate(String estimate) {
        this.estimate = estimate;
    }

    public Object getCurrencyCode() {
        return currencyCode;
    }

    public void setCurrencyCode(Object currencyCode) {
        this.currencyCode = currencyCode;
    }

    public Map<String, Object> getAdditionalProperties() {
        return this.additionalProperties;
    }

    public void setAdditionalProperty(String name, Object value) {
        this.additionalProperties.put(name, value);
    }


}

活动

    submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Retrofit retrofit=new Retrofit.Builder()
                        .baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create())
                        .build();
                PriceEstimate service=retrofit.create(PriceEstimate.class);
                Call<Prices> call=service.getEstimate(token,pick_lats,pick_Long,drop_lats,drop_Long);//token=server_token
                call.enqueue(new Callback<Prices>() {
                    @Override
                    public void onResponse(Call<Prices> call, Response<Prices> response) {
                       List<PriceModel> prices;
                        prices=response.body().getPrices();//this is null always

                    }

                    @Override
                    public void onFailure(Call<Prices> call, Throwable t) {
                        Toast.makeText(MainActivity.this,"Error",Toast.LENGTH_LONG).show();
                    }
                });
            }
        });

完成JSON日志

 {  
   "body":{  
      "additionalProperties":{  

      },
      "prices":[  

      ]
   },
   "rawResponse":{  
      "body":{  
         "contentLength":13,
         "contentType":{  
            "mediaType":"application/json",
            "subtype":"json",
            "type":"application"
         }
      },
      "code":200,
      "handshake":{  
         "cipherSuite":{  
            "javaName":"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
         },
         "localCertificates":[  

         ],
         "peerCertificates":[  
            {  
               "type":"X.509"
            },
            {  
               "type":"X.509"
            },
            {  
               "type":"X.509"
            }
         ],
         "tlsVersion":"TLS_1_2"
      },
      "headers":{  
         "namesAndValues":[  
            "Server",
            "nginx",
            "Date",
            "Sat, 16 Sep 2017 16:25:39 GMT",
            "Content-Type",
            "application/json",
            "Content-Length",
            "13",
            "Connection",
            "keep-alive",
            "Content-Geo-System",
            "wgs-84",
            "Content-Language",
            "en",
            "Etag",
            "\"170e362581d1816dbaf082a7ac196cba26bbc4f7\"",
            "X-Uber-App",
            "uberex-nonsandbox",
            "X-Uber-App",
            "optimus",
            "Strict-Transport-Security",
            "max-age\u003d604800",
            "X-Content-Type-Options",
            "nosniff",
            "X-XSS-Protection",
            "1; mode\u003dblock",
            "Strict-Transport-Security",
            "max-age\u003d2592000",
            "X-Frame-Options",
            "SAMEORIGIN",
            "Cache-Control",
            "max-age\u003d0"
         ]
      },
      "message":"OK",
      "networkResponse":{  
         "code":200,
         "handshake":{  
            "cipherSuite":{  
               "javaName":"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
            },
            "localCertificates":[  

            ],
            "peerCertificates":[  
               {  
                  "type":"X.509"
               },
               {  
                  "type":"X.509"
               },
               {  
                  "type":"X.509"
               }
            ],
            "tlsVersion":"TLS_1_2"
         },
         "headers":{  
            "namesAndValues":[  
               "Server",
               "nginx",
               "Date",
               "Sat, 16 Sep 2017 16:25:39 GMT",
               "Content-Type",
               "application/json",
               "Content-Length",
               "13",
               "Connection",
               "keep-alive",
               "Content-Geo-System",
               "wgs-84",
               "Content-Language",
               "en",
               "Etag",
               "\"170e362581d1816dbaf082a7ac196cba26bbc4f7\"",
               "X-Uber-App",
               "uberex-nonsandbox",
               "X-Uber-App",
               "optimus",
               "Strict-Transport-Security",
               "max-age\u003d604800",
               "X-Content-Type-Options",
               "nosniff",
               "X-XSS-Protection",
               "1; mode\u003dblock",
               "Strict-Transport-Security",
               "max-age\u003d2592000",
               "X-Frame-Options",
               "SAMEORIGIN",
               "Cache-Control",
               "max-age\u003d0"
            ]
         },
         "message":"OK",
         "protocol":"HTTP_1_1",
         "receivedResponseAtMillis":1505576817826,
         "request":{  
            "cacheControl":{  
               "immutable":false,
               "isPrivate":false,
               "isPublic":false,
               "maxAgeSeconds":-1,
               "maxStaleSeconds":-1,
               "minFreshSeconds":-1,
               "mustRevalidate":false,
               "noCache":false,
               "noStore":false,
               "noTransform":false,
               "onlyIfCached":false,
               "sMaxAgeSeconds":-1
            },
            "headers":{  
               "namesAndValues":[  
                  "Authorization",
                  "Token wegHf8ihFOzW2TI7pefdVz7xkst_cC3oXLvMhtmW",
                  "Host",
                  "api.uber.com",
                  "Connection",
                  "Keep-Alive",
                  "Accept-Encoding",
                  "gzip",
                  "User-Agent",
                  "okhttp/3.8.0"
               ]
            },
            "method":"GET",
            "tag":{  
               "headers":{  
                  "namesAndValues":[  
                     "Authorization",
                     "Token wegHf8ihFOzW2TI7pefdVz7xkst_cC3oXLvMhtmW"
                  ]
               },
               "method":"GET",
               "url":{  
                  "host":"api.uber.com",
                  "password":"",
                  "pathSegments":[  
                     "v1.2",
                     "estimates",
                     "price"
                  ],
                  "port":443,
                  "queryNamesAndValues":[  
                     "start_latitude",
                     "17.368908",
                     "start_longitude",
                     "17.368908",
                     "end_latitude",
                     "17.413828",
                     "end_longitude",
                     "17.413828"
                  ],
                  "scheme":"https",
                  "url":"https://api.uber.com/v1.2/estimates/price?start_latitude\u003d17.368908\u0026start_longitude\u003d17.368908\u0026end_latitude\u003d17.413828\u0026end_longitude\u003d17.413828",
                  "username":""
               }
            },
            "url":{  
               "host":"api.uber.com",
               "password":"",
               "pathSegments":[  
                  "v1.2",
                  "estimates",
                  "price"
               ],
               "port":443,
               "queryNamesAndValues":[  
                  "start_latitude",
                  "17.368908",
                  "start_longitude",
                  "17.368908",
                  "end_latitude",
                  "17.413828",
                  "end_longitude",
                  "17.413828"
               ],
               "scheme":"https",
               "url":"https://api.uber.com/v1.2/estimates/price?start_latitude\u003d17.368908\u0026start_longitude\u003d17.368908\u0026end_latitude\u003d17.413828\u0026end_longitude\u003d17.413828",
               "username":""
            }
         },
         "sentRequestAtMillis":1505576817197
      },
      "protocol":"HTTP_1_1",
      "receivedResponseAtMillis":1505576817826,
      "request":{  
         "headers":{  
            "namesAndValues":[  
               "Authorization",
               "Token wegHf8ihFOzW2TI7pefdVz7xkst_cC3oXLvMhtmW"
            ]
         },
         "method":"GET",
         "url":{  
            "host":"api.uber.com",
            "password":"",
            "pathSegments":[  
               "v1.2",
               "estimates",
               "price"
            ],
            "port":443,
            "queryNamesAndValues":[  
               "start_latitude",
               "17.368908",
               "start_longitude",
               "17.368908",
               "end_latitude",
               "17.413828",
               "end_longitude",
               "17.413828"
            ],
            "scheme":"https",
            "url":"https://api.uber.com/v1.2/estimates/price?start_latitude\u003d17.368908\u0026start_longitude\u003d17.368908\u0026end_latitude\u003d17.413828\u0026end_longitude\u003d17.413828",
            "username":""
         }

1 个答案:

答案 0 :(得分:0)

我发现自己的错误,只是在这里分享,以便将来可以帮助某人。

我的坐标不正确地传递给我的坐标,我通过了我的经度值,反之亦然。在浪费我的时间后感到非常愚蠢