如何更新要点?

时间:2022-04-15 07:23:28

I want to update my Gist from another website, where I log in with my gist token. I can't get it to work. I managed to get a gist via GET, but updating a gist with PATCH isn't working.

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

I don't think it's a problem with authentication, because when getting a gist, my username and profile showed up correctly.

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

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));
});

I keep getting an Error 400 (Bad Request).

我一直收到错误400(错误请求)。

Response:

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

Can someone point out if I'm doing something wrong? Thanks a lot.

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

1 个解决方案

#1


1  

Alright, after some fiddling this has been the problem the entire time:

好吧,经过一些摆弄,这一直是整个时间的问题:

data should be a string, not an object.

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

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

#1


1  

Alright, after some fiddling this has been the problem the entire time:

好吧,经过一些摆弄,这一直是整个时间的问题:

data should be a string, not an object.

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

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