【问题标题】:How do I update a Gist?如何更新 Gist?
【发布时间】:2016-10-12 01:54:07
【问题描述】:

我想从另一个网站更新我的Gist,我使用我的 gist 令牌登录。我无法让它工作。我设法通过 GET 获得了要点,但使用 PATCH 更新要点不起作用。

我不认为这是身份验证的问题,因为在获得要点时,我的用户名和个人资料显示正确。

JavaScript (JQuery):

$.ajax({ 
  url: 'https://api.github.com/gists/e3e0b182c09bf333593c',
  type: 'PATCH',
  beforeSend: function(xhr) { 
    xhr.setRequestHeader("Authorization","token f32e-----MY-TOKEN-(GIST-ACCESS)-----6f44"); 
  }, data: {
    "description":"Edit gist",
    "files":{
      "annexation.json":{
        "content":"{\"updated content\":\"from Ajax\"}"
      }
    }
  }
}).done(function(response) {
  $('#write').text(JSON.stringify(response));
});

我不断收到错误 400(错误请求)。

回复:

{
  "message": "Problems parsing JSON",
  "documentation_url": "https://developer.github.com/v3/gists/#edit-a-gist"
}

如果我做错了什么,有人可以指出吗?非常感谢。

【问题讨论】:

    标签: javascript json ajax xmlhttprequest gist


    【解决方案1】:

    好吧,经过一番摆弄,这一直是问题所在:

    数据应该是一个字符串,而不是一个对象。

    data: '{"description":"Edit gist","files":{"annexation.json":{"content":"{\"updated content\":\"from Ajax\"}"}}'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-28
      • 1970-01-01
      • 2010-12-31
      • 1970-01-01
      • 2017-10-27
      • 2016-09-02
      相关资源
      最近更新 更多