【问题标题】:oauth flow in github api v3 not workinggithub api v3中的oauth流不起作用
【发布时间】:2012-04-20 23:01:10
【问题描述】:

所以这应该很简单,但我似乎找不到我的失败点。希望其他人可以向我指出。

首先我去https://github.com/login/oauth/authorize?client_id=CLIENT_ID&scope=gist,这会返回一个代码给我。然后我这样做:

import requests, json

client_id = XXXX
client_secret = XXXX
code = XXXX

r = requests.post(
    'https://github.com/login/oauth/access_token', 
    data=json.dumps({
        'client_id':client_id, 
        'client_secret':client_secret,
        'code':code
    })
r.content  # this gives me a 404 header

当我访问我的测试用户时,它显示我已获得授权,我的应用显示为有一个用户,但我没有访问令牌。

我做错了什么。

【问题讨论】:

    标签: python api oauth github


    【解决方案1】:

    我是对的,这是一个非常简单的问题,但我将把它留在这里,以防其他人遇到同样的错误。

    如有疑问,请手动定义您的标题。所以你需要:

    header = {'content-type':'application/json'}
    

    然后传入header:

    r = requests.post(
        'https://github.com/login/oauth/access_token', 
        data=json.dumps({
            'client_id':client_id, 
            'client_secret':client_secret,
            'code':code
        }),
        headers=header
    )
    

    对我来说,这解决了问题。

    【讨论】:

      猜你喜欢
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-16
      • 1970-01-01
      • 2012-03-08
      • 1970-01-01
      • 2016-01-05
      相关资源
      最近更新 更多