@Roman_Remeslo

Как управлять параметрами GET запросов Retrofit?

Ну смотрите.. Я хочу управлять параметрами get-запросов, которые я задаю в Link.java, но как это сделать я не знаю.
Код:

MainActivity.java:

import androidx.appcompat.app.AppCompatActivity;
 
import android.os.Bundle;
import android.widget.TextView;
 
import java.util.List;
 
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
 
public class MainActivity extends AppCompatActivity {
    TextView text;
    Link link;
    String url = "https://mp3go.dev/";
    Retrofit retrofit;
    String pesni = "";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text = findViewById(R.id.text);
        retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).build();
        link = retrofit.create(Link.class);
        link.getSongs().enqueue(new Callback<GetSongs>() {
            @Override
            public void onResponse(Call<GetSongs> call, Response<GetSongs> response) {
                List<Song> s = response.body().getResult();
                for(int i = 0;i<s.size();i++){
                    pesni += s.get(i).getTitle()+"\n";
                }
                text.setText(pesni);
            }
 
            @Override
            public void onFailure(Call<GetSongs> call, Throwable t) {
                text.setText(t.getMessage());
 
                t.printStackTrace();
            }
        });
    }
}


Link.java:

import retrofit2.Call;
import retrofit2.http.GET;
 
public interface Link {
@GET("api/tracks.searchq=Sting&search_type=&limit=50&offset=100&api_key=997Lsdfsd6iPciVDSsdffsdewR16rewzZYfoofpf1")
    Call<GetSongs> getSongs();
}
  • Вопрос задан
  • 152 просмотра
Пригласить эксперта
Ответы на вопрос 1
@5am
первая же ссылка в гугле
https://square.github.io/retrofit/2.x/retrofit/ind...
Simple Example:


 @GET("/friends")
 Call<ResponseBody> friends(@Query("page") int page);
 
Calling with foo.friends(1) yields /friends?page=1.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы