L
L
Loyxim2021-01-25 21:33:50
Python
Loyxim, 2021-01-25 21:33:50

Why does DonationAlerts return 'Unauthenticated.'?

I'm trying to get a list of donations sent to me by users via the Donation Alerts API. It returns the error {'message': 'Unauthenticated.'}, what am I doing wrong?
The code:

import requests 
headers = { "Authorization": "Bearer токен" } 
response = requests.get('https://www.donationalerts.com/api/v1/alerts/donations', headers=headers) 
r = response.json() 
print(r)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-01-25
@Loyxim

Wrong token received, what to say
Use any available method from the documentation. Basic OAuth2 authentication
https://www.donationalerts.com/apidoc#authorization
Example of obtaining a token using Authorization Code grant type

import requests
import webbrowser
from urllib.parse import urlencode


APP_ID = 
API_KEY = ''
REDIRECT_URI = 'http://127.0.0.1:8000'
SCOPE = 'oauth-user-show oauth-donation-index'


# 2. Authorization Request
data = {'client_id': APP_ID, 'redirect_uri': REDIRECT_URI, 'response_type': 'code', 'scope': SCOPE}
url = 'https://www.donationalerts.com/oauth/authorize?' + urlencode(data)
webbrowser.open(url)

code = input('code: ')


# 4. Getting Access Token
data = {'grant_type':'authorization_code', 'client_id':APP_ID, 'client_secret': API_KEY, 'redirect_uri': REDIRECT_URI, 'code': code}
r = requests.post('https://www.donationalerts.com/oauth/token', data=data).json()

access_token = r['access_token']
refresh_token = r['refresh_token']


# Authorized Request
headers = {'Authorization': 'Bearer {}'.format(access_token)} 
response = requests.get('https://www.donationalerts.com/api/v1/alerts/donations', headers=headers) 
r = response.json() 
print(r)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question