Commit 386a3ede88

386a3ede88b6d5fb2690af6e2d39bade39d7d38e

parent: 76aa1e7653

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-20 14:04 UTC

get userid from anilist using token

Layout: unified · split

anilist.py +32
@@ -2,6 +2,38 @@ import requests
2import json 2import json
3 3
4 4
5import requests
6
7def get_anilist_user_id(token):
8 url = "https://graphql.anilist.co"
9 query = '''
10 query {
11 Viewer {
12 id
13 name
14 }
15 }
16 '''
17
18 headers = {
19 "Authorization": f"Bearer {token}",
20 "Content-Type": "application/json",
21 "Accept": "application/json"
22 }
23
24 response = requests.post(url, json={"query": query}, headers=headers)
25
26 if response.status_code == 200:
27 data = response.json()
28 user_id = data['data']['Viewer']['id']
29 user_name = data['data']['Viewer']['name']
30 return user_id, user_name
31 else:
32 raise Exception(f"Error: {response.status_code}, {response.text}")
33
34# Replace 'your_token' with your actual AniList token
35
36
5def get_user_data(access_token, user_id): 37def get_user_data(access_token, user_id):
6# Replace with your actual access token and user ID 38# Replace with your actual access token and user ID
7 # access_token = 39 # access_token =