向Github API发出发布请求以创建问题不起作用 [英] Making a Post request to Github API for creating issue is not working

查看:100
本文介绍了向Github API发出发布请求以创建问题不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几天,我一直在向github api发出此发布请求,但不幸的是,响应以错误消息"的形式返回

I have been trying to make this post request to the github api for the last couple of days, but unfortunately the response is coming back as "bad message"

这是我们在节点中使用https请求在post请求中发送的代码-

here is the piece of code we are sending in the post request using https request in node -

这是帖子数据

var issueData = JSON.stringify({
  "title":title,
  "body":comment
});

这是选项文件

var options = {
  host: 'api.github.com',
  path: '/repos/sohilpandya/katasohil/issues?access_token='+sessions.token,
  headers: {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0',
  },
  method: 'POST'
};

这是https请求

var requestaddIssue  = https.request(options, function(responseFromIssues){
  responseFromIssues.setEncoding('utf8');
  responseFromIssues.on('data', function(chunk){
    console.log('>>>>chunk>>>>>',chunk);
    issueBody += chunk;
  });
  responseFromIssues.on('end',function(issueBody){
    console.log(issueBody);
  });
});
requestaddIssue.write(issueData);
requestaddIssue.end();

我尝试了另一种方法,其中用户的身份验证令牌在标头中为

I have tried another approach where the authentication token for the user is in the header as

'Authentication': 'OAuth '+ sessions.token (where we are storing token inside sessions)

但是块响应似乎总是在控制台日志中返回以下内容.

But the chunk response always seems to come back with the following in the console log.

{
 "message": "Not Found",
 "documentation_url": "https://developer.github.com/v3/issues/#create-an-issue"
}

我在apigee中尝试了相同的方法,它似乎可以正常运行,并返回正确的响应.希望有人可以在上面的代码中找到导致此错误消息错误的小错误.

I have tried the same in apigee and it seems to work ok and returns to correct response. Hoping someone can find the minor error in the code above that is causing this bad message error.

推荐答案

除了在您发布的代码段中未定义issueBody变量外,代码都是正确的.我尝试使用个人访问令牌.

Except the issueBody variable is not defined in the snippets you posted, the code is correct. I tried it using a personal access token.

出现错误是因为您需要添加范围未解决的问题.

The error you get appears because you need to add a scope with power to open issues.

我尝试了repopublic_repo范围,它们都起作用.请注意,repo可以访问私有存储库.在这里,您可以看到范围列表.

I tried the repo and public_repo scopes and they are both working. Note that repo has access to private repositories. Here you can see the list of scopes.

如果您使用的是OAuth,那么您应该拥有一个类似于以下内容的网址:

If you're using OAuth, then you you should have an url looking like this:

https://github.com/login/oauth/authorize?client_id=<client-id>&scope=public_repo&redirect_uri=<redirect-uri>

这篇关于向Github API发出发布请求以创建问题不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆