我正在尝试将 github 问题 api 集成到一个项目中。我想我正在遵循 oauth 的规则,以及http://develop.github.com/p/issues.html上需要和提到的所有内容,但它似乎不起作用。我没有收到详细的错误消息,只有 401。
- 我在 github(api v2) 注册了一个 oauth 应用程序,并提供了回调 url。
- 我构造了身份验证网址:https ://github.com/login/oauth/authorize?client_id=...&redirect_uri=http://.../no_port/
- 他们为我发布代码(请求令牌),我将其交换为访问令牌,它工作正常。问题:
- 我可以在自己的 repos 上查看自己的问题,但如果我只是一个合作者,那就是 401(未经授权)
- 即使在我自己的仓库中,也无法创建新问题: POST: http://github.com/api/v2/json/issues/open/:user/:repo PARAMS: body=&login=&token=6&title=
使用 django、python 的实际实现:
url = 'https://github.com/login/oauth/access_token?client_id=%(client_id)s&redirect_uri=%(redirect_uri)s&client_secret=%(client_secret)s&code=%(code)s' % locals()
req = urllib2.Request(url)
response = urllib2.urlopen(req).read()
access_token = re.search(r'access_token=(\w+)', response).group(1)
url = 'http://github.com/api/v2/json/issues/open/%(user)s/%(repo)s' % locals()
params = urllib.urlencode({'login': user, 'token': access_token, 'title': 'title', 'body': 'body'})
req = urllib2.Request(url, params)
try:
response = urllib2.urlopen(req)
except HTTPError, e:
return HttpResponse('[*] Its a fckin %d' % e.code)
except URLError, e:
return HttpResponse('[*] %s\n' % repr(e.reason))
else:
resp = json.loads(response.read())