使用Python请求刷新Reddit API的令牌

时间:2018-10-06 20:09:10

标签: python api oauth-2.0 python-requests

我想刷新访问令牌,但是我的代码以某种方式返回空响应

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())

您能帮我找到错误吗?

1 个答案:

答案 0 :(得分:0)

错误的标题

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