Cannot create new Gist File
See original GitHub issueSo far, I’ve been able to do the following:
Authenticate with a user token.
GitHub gitHub = GitHub.connectUsingOAuth(token);
boolean authenticated = gitHub.isCredentialValid();
Once authenticated I’ve been able to…
Pull list of users gists:
gitHub.getMyself().listGists()
Create NEW Gists with a file included:
gitHub.createGist()
.file(filename,contents)
.description(description)
.public_(isPublic)
.create();
Delete Gists:
gitHub.getGist(gistId).delete();
Get a list of files within a given gist:
GHGist gist = gitHub.getGist(gistId);
List<String> fileNameList = new ArrayList<>();
for (String filename : gist.getFiles().keySet()) {
fileNameList.add(filename);
}
Though I cannot get the contents of a file this way, I have to pull the files’ URL and then get the contents of the file like this:
String fileContents = "";
GHGistFile file = gitHub.getGist(gistId).getFile(fileName);
try {
HttpURLConnection conn = gitHub.getConnector().connect(new URL(file.getRawUrl()));
conn.setRequestMethod("GET");
InputStream is = conn.getInputStream();
fileContents = IOUtils.toString(is, StandardCharsets.UTF_8);
is.close();
}
catch (IOException e) {e.printStackTrace();}
return fileContents;
THOSE are the things I CAN do … what I CAN’T seem to do with the API is anything at the gist file level where I need to delete a file, add a file, or update the contents of a file. For example, this code DOES NOT GENERATE ANY ERRORS, yet it simply does not work, meaning that the file is never created inside the gist:
public static void addFileToGist(String filename, String contents, String gistId) {
GHGist gist = getGist(gistId);
try{
gist.update().addFile(filename,contents);
CustomAlert.showInfo("File Added");
}
catch (IOException e) {e.printStackTrace();}
}
Am I doing something wrong? Or is there a way to do what I need to do but I just can’t seem to figure it out? Such as - do I need to create new gist files and update them etc. via the HTTPConnector? If so, can someone who me an example of how to do that?
Mike
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)
Top GitHub Comments
@bitwiseman - YES, 1.300 gets me connected with the HttpClientGitHubConnector.
You guys work fast over there - Thank you!
😃
@bitwiseman - You certainly won’t get any arguments from me on that statement!