Get Github Authorization Token with proper scope,print to console
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$.ajax({
url: 'https://api.github.com/authorizations',
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization",
"Basic" + btoa("USERNAME:PASSWORD"));
},
data: '{"scopes":["gist"],"note":"ajax gist test for a user"}'
}).done(function(response) {
console.log(response);
});
//Create a Gist with token from above
$.ajax({
url:'https://api.github.com/gists',
type:'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization",
"token TOKEN-FROM-AUTHORIZATION-CALL");
},
data: '{"description": "a gist for a user with token api call via ajax","public": true,"files": {"file1.txt": {"content": "String file contents via ajax"}}}'
}).done(function(response) {
console.log(response);
});