2017-05-31 36 views
1
URL query string "q={city}" must not have replace block 

我不能得到這個工作,我已經嘗試了幾個其他變種,但仍然得到某種形式的例外。如何在Retrofit 2.0+中正確設置註釋和查詢?

public interface WeatherInterface { 

    @GET("/weather?q={city}") 
    Call<WeatherModel> getWeather(@Query("city") String city); 

} 

/////

public interface WeatherInterface { 

    @GET("/weather") 
    Call<WeatherModel> getWeather(@Query("q") String city); 

} 

等。

WeatherActivity.class

Call<WeatherModel> call = weatherInterface.getWeather("""CITYNAME"""); 
     call.enqueue(new Callback<WeatherModel>() { 
      @Override 
      public void onResponse(Call<WeatherModel> call, Response<WeatherModel> response) { 
       if(response.isSuccessful()) { 
        **///FIRST VARIANT FAILS HERE** 
        city.setText(response.body().getName()); 
       } 
       **///SECOND VARIANT FAILES RESPONSE** 
       else Log.d("No response", "RESPONSE"); 
      } 

      @Override 
      public void onFailure(Call<WeatherModel> call, Throwable t) { 
       Log.d("fail", "fail"); 
      } 
     }); 

編輯: Log.d(。call.request()URL()的toString(), 「呼叫請求URL」);

我應該分享我的解決方案太可能了,我只記錄了通話的URL。

回答

0

我忘了在url中添加我的API KEY。我可恥地撤回我的問題。

0

U可以使用此示例採取例如:

public interface GitHubClient { 
     @GET("https://stackoverflow.com/users/{user}/repos") 
     Call<List<GitHubRepo>> reposForUser(
      @Path("user") String user 
     ); 
    } 

更多的樣品只需訪問該website

+0

是的,我查了資料,但顯然我的API密鑰不見了。該日誌還顯示瞭如何幫助任何人的url調用。 – JoSem

相關問題