简体   繁体   中英

Refresh token for Reddit API using Python requests

I want to refresh access token but somehow my code returns empty response

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

where refresh_data is

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

Here is code

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

can you help me find the error ?

标头错误

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM