{"id":21934078,"url":"https://github.com/clxrityy/next-spotify-stats","last_synced_at":"2025-04-19T21:42:57.072Z","repository":{"id":189846568,"uuid":"681398624","full_name":"clxrityy/next-spotify-stats","owner":"clxrityy","description":"Fetch information and statistics about any Spotify artist","archived":false,"fork":false,"pushed_at":"2024-12-31T16:33:24.000Z","size":621,"stargazers_count":3,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T13:35:23.907Z","etag":null,"topics":["api","flask","nextjs","python-api","spotify-api","typescript"],"latest_commit_sha":null,"homepage":"https://next-spotify-stats.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clxrityy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-21T23:54:47.000Z","updated_at":"2024-12-31T16:33:21.000Z","dependencies_parsed_at":"2024-05-22T18:25:10.641Z","dependency_job_id":"96f1099e-9390-46cb-9646-5628e9e04d8c","html_url":"https://github.com/clxrityy/next-spotify-stats","commit_stats":null,"previous_names":["clxrityy/next-spotify-stats"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clxrityy%2Fnext-spotify-stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clxrityy%2Fnext-spotify-stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clxrityy%2Fnext-spotify-stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clxrityy%2Fnext-spotify-stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clxrityy","download_url":"https://codeload.github.com/clxrityy/next-spotify-stats/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249812165,"owners_count":21328936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","flask","nextjs","python-api","spotify-api","typescript"],"created_at":"2024-11-29T00:14:29.909Z","updated_at":"2025-04-19T21:42:57.055Z","avatar_url":"https://github.com/clxrityy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [\u003cdiv style='display:flex;gap:10px;align-items:center;justify-conent:center;'\u003e\u003cimg src='public/logo.png' alt='logo' style='width:25px;height:25px;' /\u003e NEXT SPOTIFY STATS\u003c/div\u003e](https://next-spotify-stats.vercel.app/)\n\n## Use Python to connect to Spotify's API\n\n- Create a developer Spotify application. (https://developer.spotify.com/dashboard)\n- Add your client id \u0026 secret to `.env`.\n- Load your environment variables\n\n```py\nfrom dotenv import load_dotenv\nimport os\n\nload_dotenv()\nclient_id = os.getenv('SPOTIFY_CLIENT_ID')\nclient_secret = os.getenv('SPOTIFY_CLIENT_SECRET')\n```\n\n- Define a function to generate your authentication token \u0026 headers.\n    - See [Spotify's Web API Documentation](https://developer.spotify.com/documentation/web-api/tutorials/getting-started) for more information on how this works.\n    - Send a POST request to the token endpoint URI. (`\"https://accounts.spotify.com/api/token\"`)\n\n```py\nimport base64\nfrom requests import post\nimport json\n\ndef get_token():\n    auth_string = f\"{client_id}:{client_secret}\"\n    auth_bytes = auth_string.encode('utf-8')\n    auth_base64 = str(base64.b64.encode(auth_bytes), 'utf-8')\n\n    url = \"https://accounts.spotify.com/api/token\"\n    headers = {\n        \"Authorization\": \"Basic \" + auth_base64,\n        \"Content-Type\": \"application/x-www-form-urlencoded\"\n    }\n    data = {\n        \"grant-type\": \"client_credentials\"\n    }\n\n    result = post(url=url, headers=headers, data=data)\n    json_result = json.loads(result.content)\n    token = json_result['access_token']\n\n    return token\n\ndef get_auth_header(token):\n    return {\n        \"Authorization\": \"Bearer \" + token\n    }\n```\n\n## Create API routes with Flask\n\n```zsh\npip install flask\n```\n\n```py\nfrom flask import Flask\n\napp = Flask(__name__)\n\nif __name__ == \"__main__\":\n    app.run(load_dotenv=True)\n```\n\n### Example route\n\n```py\n# http://127.0.0.1:5328/api/python\n@app.route(\"/api/python\")\ndef hello_world():\n    return f\"\u003ch1\u003eHello World\u003c/h1\u003e\"\n```\n\n## Display data on the front end\n\n- Create an example route to fetch an example piece of data, such as your access token.\n\n```py\ntoken = get_token()\n\n@app.route(\"/api/token\")\ndef tokenRoute():\n    return token\n```\n\n- Now fetch the data in a client component.\n\n`/components/Token.tsx`\n\n```tsx\n'use client';\nimport React, { useCallback } from 'react';\n\nconst Token = async () =\u003e {\n\n    async function getData() {\n        const res = await fetch('http://127.0.0.1:5328/api/token');\n\n        if (!res.ok) {\n            throw new Error(\"Failed to fetch data\")\n        }\n        return res.json();\n    }\n\n    const data = await getData();\n\n    return (\n        \u003cp\u003e\n            {data}\n        \u003c/p\u003e\n    )\n\n}\n```\n\n## Template repository from Vercel\n\nView vercel's `nextjs-flask` template [here](https://nextjs-flask-starter.vercel.app/).\n\n```zsh\nnpx create-next-app nextjs-flask --example \"https://github.com/vercel/examples/tree/main/python/nextjs-flask\"\n```\n\n### —\n\n\u003e The Flask server will be running on http://127.0.0.1:5328 – feel free to change the port in `package.json` (you'll also need to update it in `next.config.js`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclxrityy%2Fnext-spotify-stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclxrityy%2Fnext-spotify-stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclxrityy%2Fnext-spotify-stats/lists"}