改造查询参数添加apiKey

时间:2018-10-15 03:06:08

标签: kotlin retrofit

我正在使用Kotlin开发新闻源应用程序。

private void getSqlDetails() {
    final String url= "http://10.0.2.2/SureTextImage/QData.php?image_name="+getUser;
    pd.show();
    StringRequest stringRequest = new StringRequest(Request.Method.GET,
            url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    pd.hide();
                    try {

                        JSONArray jsonarray = new JSONArray(response);
                        for(int i=0; i < jsonarray.length(); i++) {
                            JSONObject jsonobject = jsonarray.getJSONObject(i);
                            String name=jsonobject.getString("image_name");
                            String imageURL=jsonobject.getString("image_path");
                            result.setText(imageURL);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if(error != null){

                        Toast.makeText(getApplicationContext(), "Something went wrong.", Toast.LENGTH_LONG).show();
                    }
                }
            }

    );

这是通过查询参数添加public interface NewsAPI { @GET("v2/top-headlines") fun getTooNews( @Query("my_apiKey") String "apiKey"); ) } 的正确方法吗?

https://square.github.io/retrofit/

1 个答案:

答案 0 :(得分:3)

否。请使用apiKey:String而不是字符串“ apiKey”。:)