0

I have a link and an API:

@GET("users/{username}")
Call<String> getStringResponse(@Path("username") String username);

public class APIClientDetail {

public Retrofit getRetrofit(String baseUrl) {
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(ScalarsConverterFactory.create())
            // add other factories here, if needed.
            .build();

        return retrofit;
    }
}

I call:

APIClientDetail apiClientDetail= new APIClientDetail();
    Retrofit retrofit= apiClientDetail.getRetrofit("https://www.youtube.com/watch?v=");

    GitHubService scalarService = retrofit.create(GitHubService.class);
    Call<String> stringCall = scalarService.getStringResponse("EMyW7WvhEso");
    stringCall.enqueue(new Callback<String>() {
        @Override
        public void onResponse(Call<String> call, Response<String> response) {
            if (response.isSuccessful()) {
                String responseString = response.body();
                // todo: do something with the response string
                modelInterface.dataSuccessful();
            }
        }

        @Override
        public void onFailure(Call<String> call, Throwable t) {
            modelInterface.dataError();
        }
    });

But it don't work, not into the function onResponse.

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Trang Đỗ
  • 160
  • 1
  • 9
  • does it go to `onFailure` ?! can you print the `t.getMessage()` in onFailure and add it to your question here to see have more clue on whats happening ? – SepJaPro2.4 Jan 30 '18 at 10:41
  • before checking if condition , just put a log and see what response you are getting – MaYur MahAjan Jan 30 '18 at 11:11
  • when i use link: gateway.fpts.com.vn/g5g/fpts/?s=realtime_index_ho ---------------- baseUrl: gateway.fpts.com.vn/g5g/fpts ---------------------- @GET("") Call getStringResponse(@Query("s") String name); It don't work! – Trang Đỗ Jan 31 '18 at 02:17

1 Answers1

1
@GET("users/{username}")

If your base url is https://www.youtube.com/watch?v=, then the url being created by retrofit for the method getStringResponse() is https://www.youtube.com/watch?v=users/EMyW7WvhEso.

Your base url should be https://www.youtube.com/ and define your api like the following:

@GET("watch")
Call<String> getVideo(@Query("v") String videoID);
denvercoder9
  • 2,979
  • 3
  • 28
  • 41
  • Thank you! It's good work. But when i use link: http://gateway.fpts.com.vn/g5g/fpts/?s=realtime_index_ho baseUrl: http://gateway.fpts.com.vn/g5g/fpts/ @GET("") Call getStringResponse(@Query("s") String name); It don't work! – Trang Đỗ Jan 31 '18 at 02:07
  • add a slash at the end of the baseurl – denvercoder9 Jan 31 '18 at 05:11
  • I did add but it don't work! :( Retrofit retrofit= apiClientDetail.getRetrofit("http://gateway.fpts.com.vn/g5g/fpts/"); It error: "Missing either GET URL or Url parameter." – Trang Đỗ Jan 31 '18 at 18:21
  • @TrangĐỗ check out this answer: https://stackoverflow.com/a/40062661/2235972 Basically use `@GET(".")` if you want to keep it empty – denvercoder9 Jan 31 '18 at 18:46