Hey everyone! I’m working on a small Adobe Air app and I need some help with the Github Gist API. I’m trying to create a new gist programmatically, but I’m running into some issues.
I’ve been using the XMLHttpRequest
object for making cross-domain requests (since Adobe Air doesn’t have the same domain restrictions as regular web browsers). However, I’m hitting a wall when it comes to authentication and actually making the POST request to create the gist.
Can anyone walk me through the process of authenticating with the Github API and then creating a new gist? I’m not sure if I need to use OAuth or if there’s a simpler way to do this.
Here’s a basic example of what I’ve tried so far:
let xhr = new XMLHttpRequest();
xhr.open('POST', 'https://api.github.com/gists', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 201) {
console.log('Gist created successfully!');
}
};
let gistData = {
description: 'My new gist',
public: true,
files: {
'file1.txt': {
content: 'Hello, Gist!'
}
}
};
xhr.send(JSON.stringify(gistData));
But this doesn’t work because I’m not authenticated. Any help would be greatly appreciated!