2017-09-16 2 views
0

Ich versuche, die Tarifschätzungen von Uber in meiner Android-App anzuzeigen, benutze Retrofit, um Daten von api zu laden, ich erhalte sogar Statuscode = 200 (was laut Uber docs sein sollte) , aber meine Preisliste ist null immer, egal welche Koordinaten ich auswähle.Uber api gibt null zurück

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

Preisklasse:

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

} 

Preis Modell:

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


} 

Aktivität

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

komplette JSON log

{ 
    "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

was gibt 'response.body()' zurück? – joao86

+0

Wenn ich den Debugger verwende, um den Wert des Körperobjekts zu überprüfen, werden folgende Werte angezeigt ------- additionalProperties = {HashMap @ 5000} size = 0 prices = {ArrayList @ 5001} size = 0 shadow $ _klasse_ = {Klasse @ 4859} "class com.sohail.farecompare.Prices" shadow $ _monitor_ = -2006322734 –

+0

log deine json antwort in logcat und post, dass hier –

Antwort

0

Nun, ich fand meinen eigenen Fehler, nur hier teilen, so dass es in Zukunft jemand helfen könnte.

Ich übermittelte meine Koordinaten falsch für Breitengrade ich passierte meine Längenwerte und umgekehrt. fühle mich wirklich dumm, nachdem ich meine Zeit dahinter verschwendet habe