改造错误 - 缺少@GET URL或@Url参数

ank*_*bbr 35 android retrofit retrofit2

我正在开发Youtube API.基本网址为https://www.googleapis.com/youtube/v3/search/ 请求:GET https://www.googleapis.com/youtube/v3/search?part=snippet&q= {search_keyword}&key = {API_键}

ApiService接口代码 -

https://www.googleapis.com/youtube/v3/search?part=snippet&q={search_keyword}&key={API_KEY}
Run Code Online (Sandbox Code Playgroud)

错误:java.lang.IllegalArgumentException:缺少@GET URL或@Url参数. 在代码行中

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

我是初学者.请帮忙!

Jak*_*ton 120

使用https://www.googleapis.com/youtube/v3/作为基本URL,然后@GET("search/")在您的服务方法上声明,这在语义上更正确 .

也就是说,如果您确实希望基本URL成为完整路径,则可以使用该路径@GET(".")声明您的最终URL与基本URL相同.

  • 为什么要加“.” 而不是什么都不加??看起来很混乱 (5认同)
  • 我喜欢那个“。” (3认同)
  • 哇!我的网址是 http://www.omdbapi.com/?s=star war 。它有效,谢谢 (2认同)