-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedly_client.py
32 lines (29 loc) · 1.17 KB
/
feedly_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
class FeedlyClient:
def __init__(self, client_id, client_secret, access_token=None):
self.client_id = client_id
self.client_secret = client_secret
self.access_token = access_token
def get_access_token(self, redirect_uri, code):
url = "https://cloud.feedly.com/v3/auth/token"
headers = {"Content-Type": "application/json"}
data = {
"client_id": self.client_id,
"client_secret": self.client_secret,
"grant_type": "authorization_code",
"redirect_uri": redirect_uri,
"code": code
}
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
self.access_token = response.json()["access_token"]
return self.access_token
def api_request(self, endpoint, params=None):
headers = {
"Authorization": f"Bearer {self.access_token}",
"Content-Type": "application/json"
}
url = f"https://cloud.feedly.com/v3/{endpoint}"
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
return response.json()