github 出现 api 401 问题,为什么? (姜戈)
我正在尝试将 github issues 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/
- 他们为我发布了代码(请求令牌),我将其交换为访问令牌,效果很好。 问题:
- 我可以在自己的存储库上查看自己的问题,但如果我只是一个协作者,则会出现 401(未经授权)
- 无法创建新问题,即使是在我自己的存储库上: 邮政: http://github.com/api/v2/json/issues/open/:user /:仓库 参数: 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())
I'm trying to integrate github issues api into a project. I think I'm following the rules of oauth, and everything that is needed and mentioned on http://develop.github.com/p/issues.html,
but it doesn't seem to work. I don't get detailed error message, just a 401.
- i registered an oauth app at github(api v2), and provided the callback url.
- i construct the auth url: https://github.com/login/oauth/authorize?client_id=...&redirect_uri=http://.../no_port/
- They post the code for me(request token), i exchange it ho access token, it works fine.
The problems: - I can watch my own issues on my own repos, but if i'm just a collaborator, it's 401(unauthorized)
- There's no way to create a new issue, even on my own repo:
POST:
http://github.com/api/v2/json/issues/open/:user/:repo
PARAMS:
body=&login=&token=6&title=
actual implementatios with 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())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题可能是..
您指定标题参数具有“title”的字面值,与“body”相同。
你可能想要这个吗? ..
Could the problem be..
You specify that the title param has the literal value of 'title', same with 'body'.
Do you possibly want this instead? ..
我不知道这是否正是您所需要的,但这是我在我的项目之一中用于打开问题的代码:
I don't know if it is exactly what you need, but this is the code I use in one of my project to open issues: