I give the request and get this error:

Caused by: java.lang.IllegalArgumentException: URL query string "q = select *% 20 from% 20yahoo.finance.quote% 20where% 20symbol% ​​20in% 20 ({names}) & format = json & diagnostics = true & env = store% 3A% 2F% 2Fdatatables.org% 2Falltableswithkeys "must block. For dynamic query parameters use @Query. for method SharesAPI.getData

My query interface:

public interface SharesAPI { @GET("yql?q=select *%20from%20yahoo.finance.quote%20where%20symbol%20in%20({names})&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys") Call<List<Shares>> getData(@Path("names") String stockIndexes); Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://query.yahooapis.com/v1/public/") .addConverterFactory(GsonConverterFactory.create()) .build(); } 

My activation and response is:

 public class InformationActivity extends AppCompatActivity { @BindView(R.id.tvAnswer) TextView tvAnswer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_graph); ButterKnife.bind(this); final SharesAPI sharesAPI = SharesAPI.retrofit.create(SharesAPI.class); ShareService shareService = new ShareService(); String[] indexs = new String[]; indexs[0] = "AAPL"; indexs[1] = "MCD"; indexs[2] = "GOOG"; indexs[3] = "AMZN"; indexs[4] = "GPRO"; final Call<List<Shares>> call = sharesAPI.getData(shareService.joinShares(indexs)); call.enqueue((new Callback<List<Shares>>() { @Override public void onResponse(Call<List<Shares>> call, Response<List<Shares>> response) { // response.isSuccessfull() возвращает true если код ответа 2xx if (response.isSuccessful()) { Shares shares = (Shares) response.body(); tvAnswer.setText(shares.getIndex()); tvAnswer.setText(shares.getName()); tvAnswer.setText(shares.getCost()); // Выводим посты по отдельности } else { int statusCode = response.code(); // handle request errors yourself ResponseBody errorBody = response.errorBody(); try { tvAnswer.setText(errorBody.string()); } catch (IOException e) { e.printStackTrace(); } } } @Override public void onFailure(Call<List<Shares>> call, Throwable t) { tvAnswer.setText("Что-то пошло не так: "); } })); } } 

The class that my array translates into strings and adds quotes with commas for the query:

 public class ShareService { private SharesAPI api; public Call<List<Shares>> getShares(String[] indexes) { return api.getData(joinShares(indexes)); } public String joinShares(String[] indexes) { StringBuilder builder = new StringBuilder("\""); for (int i = 0; i < indexes.length; i++) { if (i == indexes.length-1) { builder.append(indexes[i]); builder.append("\""); } else { builder.append(indexes[i]); builder.append("\",\""); } } return builder.toString(); } } 

    1 answer 1

    Because it is impossible to thrust dynamic parameters into the request path. The path must be separately, the parameters separately.

     public interface SharesAPI { @GET("yql) Call<List<Shares>> getData(@Query("q") String query, @Query("format") String format, @Query("diagnostics") boolean diagnostics, @Query("env") String env); } 

    And then call, forming the value of the parameters dynamically

     String query = "select * from yahoo.finance.quote where symbol in (" + shareService.joinShares(indexs) + ")"; sharesAPI.getData(query, "json", true, "store://datatables.org/alltableswithkeys");