简体   繁体   English

Android开发和改造

[英]Android Development and retrofit

My Question is simple i want to retrieve my github repos with the help github api using retrofit in android, So i am little confuse how to pass my github username to url i have tried but it give me error message. 我的问题很简单,我想使用android中的Retrofit借助Help github api检索我的github仓库,所以我有点困惑如何将github用户名传递给我尝试过的url,但这给了我错误消息。 This is my webservice URL for retrieving my github repos : https://api.github.com/users/mshahzaib374/repos . 这是用于检索github仓库的Web服务URL: https : //api.github.com/users/mshahzaib374/repos Here you can see my username is mshahzaib374 , So how can i pass my username to url as parameter. 在这里您可以看到我的用户名是mshahzaib374 ,那么我如何将我的用户名传递给url作为参数。 I hope you understand my question, I am attaching code snippets and error screen please see it, Thanks for advance. 希望您理解我的问题,我正在附加代码段和错误屏幕,请查看它,谢谢。

Retrofit homepage contains sample code that very similar to what you want: 改造主页包含与所需代码非常相似的示例代码:

public interface GitHubService {
  @GET("users/{user}/repos")
  Call<List<Repo>> listRepos(@Path("user") String user);
}

So, to insert username in URL you have to substitute part of URL with some name in curly braces and add corresponding parameter to method marked with @Path("<your parameter name>") annotation. 因此,要在URL中插入用户名,您必须用大括号中的名称替换URL的一部分,并将相应的参数添加到标有@Path("<your parameter name>")注释的方法中。

You can make a GET API call like this 您可以像这样进行GET API调用

GET /users/:username/repos

Check this out the official GIT api documentation. 查阅官方GIT api文档。

Hope it helps you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM