Files
hiffi-artist-intelligence/collectors/test_spotify_endpoints.py
T

34 lines
1.1 KiB
Python
Raw Normal View History

"""
Manual diagnostic utility for testing public and authenticated Spotify API endpoints.
Excluded from automated pytest discovery.
"""
import os
from pathlib import Path
import requests
__test__ = False
def run_manual_endpoint_test(token: str):
"""Manual probe for validating token scopes against official Spotify Web API endpoints."""
headers = {"Authorization": f"Bearer {token}"}
sample_id = "06HL4z0CvFAxyc27GXpf02" # Taylor Swift
url = f"https://api.spotify.com/v1/artists/{sample_id}"
resp = requests.get(url, headers=headers, timeout=10)
print(f"Status Code: {resp.status_code}")
if resp.status_code == 200:
data = resp.json()
print(f"Artist Name: {data.get('name')}")
print(f"Followers: {data.get('followers', {}).get('total')}")
else:
print(f"Error Payload: {resp.text}")
if __name__ == "__main__":
test_token = os.getenv("SPOTIFY_ACCESS_TOKEN", "").strip()
if not test_token:
print("Usage: Set SPOTIFY_ACCESS_TOKEN in environment before executing.")
else:
run_manual_endpoint_test(test_token)