Retrofit error-Missing either @GET URL or @Url parameter

风格不统一 提交于 2019-12-03 10:32:43

问题


I am working on Youtube API. The base URL is <https://www.googleapis.com/youtube/v3/search/>

Request :GET

https://www.googleapis.com/youtube/v3/search?part=snippet&q={search_keyword}&key={API_KEY}

ApiService Interface code-

public interface ApiService {
    @GET("")
    Call<YoutubeResponse> searchVideos(@Query("part") String part,
                                   @Query("q") String q,@Query("key") String apiKey);
}

The error: java.lang.IllegalArgumentException: Missing either @GET URL or @Url parameter. in the line of code

Call<YoutubeResponse> call=service.searchVideos("snippet",s, URLConstants.Youtube_API_KEY);

I'm a beginner. Please help!


回答1:


It's much more semantically correct to use https://www.googleapis.com/youtube/v3/ as your base URL and then declare @GET("search/") on your service method.

That said, if you really want your base URL to be the full path you can use @GET(".") to declare that your final URL is the same as your base URL.



来源:https://stackoverflow.com/questions/40062564/retrofit-error-missing-either-get-url-or-url-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!