【问题标题】:Python authorize imgur OAuth2.0 authentication to fetch subreddit galleryPython授权imgur OAuth2.0认证获取subreddit画廊
【发布时间】:2013-02-10 01:29:40
【问题描述】:

所以我正在尝试访问 imgur API 以获取某个 reddit 子图库中的图像列表。这是我迄今为止尝试过的:

>>> header = {'client_id': 'thisismyclientid', 'response_type': 'pin'}
>>> r = requests.get('https://api.imgur.com/oauth2/authorize', headers=header, verify=False)
>>> r.text
u'{"data":{"error":"client_id and response_type are required","request":"\\/oauth2\\/authorize","parameters":"","method":"GET"},"success":false,"status":400}'

不完全确定我做错了什么,这不是传递我的 client_id 和响应类型的正确方法吗?

【问题讨论】:

    标签: python api authentication imgur


    【解决方案1】:

    快速查看文档会发现:

    https://api.imgur.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=REQUESTED_RESPONSE_TYPE&state=APPLICATION_STATE
    

    这些是获取参数,而不是标题。所以你必须将字典传递为params 而不是headers

    【讨论】:

    • 非常感谢!我不敢相信我没有意识到这一点:|百万谢谢!
    • 没问题。我建议反对 使用verify=False(如果您使用的是python 2,则必须这样做,否则它将无法正常工作)。如果你有 python3.2 尝试删除 verify=False
    猜你喜欢
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 1970-01-01
    • 2019-09-20
    • 2018-12-11
    • 1970-01-01
    • 2021-02-26
    • 2019-10-13
    相关资源
    最近更新 更多