在过去的几个小时里,我一直在尝试通过他们的 API 更新 GitHub Gist,但无济于事。我可以轻松地 POST 到https://api.github.com/gists并创建一个新的 Gist,但我永远无法获得https://api.github.com/gists/:id的补丁来工作。如何通过他们的 API 更新 Gists?我错过了一些重要的细节吗?
这是我目前困境的 JSFiddle:http: //jsfiddle.net/ZzUsv/4/
代码本身:
var Gist = Backbone.Model.extend({
urlRoot: 'https://api.github.com/gists',
defaults: {
description: 'A terse gist',
'public': true,
files: {
'html.html': {
content: 'test'
},
'css.css': {
content: 'test'
},
'js.js': {
content: 'test'
}
}
}
});
var my_gist = new Gist;
my_gist.save( my_gist.toJSON(), {
success: function(){
$('body').append('successfully created gist');
my_gist.save({ description: '<div>A less terse gist</div>' }, {
patch: true,
success: function(){
$('body').append('<div>successfully updated gist</div>');
},
error: function( model, xhr, options ){
$('body').append('<div><b>error updating gist</b></div>');
$('body').append( JSON.stringify( xhr ) );
}
});
}
});
相关文档:http: //developer.github.com/v3/gists/#edit-a-gist