【问题标题】:Refresh token for Reddit API using Python requests使用 Python 请求刷新 Reddit API 的令牌
【发布时间】:2019-03-11 23:36:01
【问题描述】:

我想刷新访问令牌,但不知何故我的代码返回空响应

response = requests.post(auth_url,data=refresh_data,auth=client_auth,headers=headers)

refresh_data 在哪里

refresh_data = {'grant_type' : 'refresh_token',
'refresh_token' : '31763629822-aRVYmfxTAW4Sx5mihFB89sqwQno'
}

这是代码

import requests
import requests.auth
from requests import Request
from bs4 import BeautifulSoup
import json
url = 'https://www.reddit.com/dev/api/'

oauth_url = 'https://oauth.reddit.com/'

auth_url = 'https://www.reddit.com/api/v1/access_token'

CLIENT_ID = 'api key'
CLIENT_SECRET = 'api secret'

refresh_data = {'grant_type' : 'refresh_token', 'refresh_token' : '31763629822-aRVYmfxTAW4Sx5mihFB89sqwQno'}

headers = {'User Agent' : 'Test Client v/1.0 '}


 response = requests.post(auth_url,data=refresh_data,auth=(CLIENT_ID,CLIENT_SECRET),headers=headers)

print(response.json())

你能帮我找出错误吗?

【问题讨论】:

  • 你能得到更多细节,以便我测试我的想法
  • @kcorlidy 我想发出刷新令牌的发布请求,但不知怎的,我得到了来自 reddit api 的空白响应或太多的请求错误。我用代码编辑了问题
  • @kcorlidy 感谢您的宝贵时间,我解决了我的问题。我在User-Agent 中忘记了-。愚蠢的我试图解决问题将近 6 个小时。好吧,我想这就是编程的真正含义。 ;)

标签: python api oauth-2.0 python-requests


【解决方案1】:

错误的标题

headers = {'User-Agent' : 'Test Client v/1.0 '}

【讨论】:

    猜你喜欢
    • 2021-11-27
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 2020-06-02
    相关资源
    最近更新 更多