I also doing that same Requirement To get List of repositories of a particular user
Try this one you will get All repositories of that user
//Here name means username of GitHub account
public Collection<AuthMsg> getRepos(String name) {
String url = "https://api.github.com/users/"+name+"/repos";
String data = getJSON(url);
System.out.println(data);
Type collectionType = new TypeToken<Collection<AuthMsg>>(){}.getType();
Collection<AuthMsg> enums = new Gson().fromJson(data, collectionType);
return enums;
}
//getJson method
public String getJSON(String url) {
HttpURLConnection c = null;
try {
URL u = new URL(url);
c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setRequestProperty("Content-length", "0");
c.setUseCaches(false);
c.setAllowUserInteraction(false);
c.connect();
int status = c.getResponseCode();
switch (status) {
case 200:
case 201:
BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line+"\n");
}
br.close();
return sb.toString();
}
} catch (MalformedURLException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} finally {
if (c != null) {
try {
c.disconnect();
} catch (Exception ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
}
return null;
}
//AuthMsg Class
public class AuthMsg {
//"name" which is in json what we get from url
@SerializedName("name")
private String repository;
/**
* @return the repository
*/
public String getRepository() {
return repository;
}
/**
* @param repository the repository to set
*/
public void setRepository(String repository) {
this.repository = repository;
}
}