A two-part tutorial explains how to configure the credentials needed to automate syncing a YouTube playlist to a Spotify playlist. For Spotify, it instructs users to create a Spotify developer app on developer.spotify.com with the Web API enabled and a redirect URI of http://127.0.0.1:8888/callback. After saving the app, users copy the app’s Client ID and Client Secret from the app settings. The tutorial then walks through a one-time login to obtain a long-lived refresh token: users open a Spotify authorization URL using their Client ID, accept playlist permissions, extract the code from the callback URL, and exchange that code for tokens via curl (or PowerShell) against Spotify’s token endpoint. The resulting refresh_token is stored for unattended daily runs, while the access token expires after about an hour. The tutorial’s next chapter covers YouTube setup in Google Cloud Console: users create or select a project, enable the YouTube Data API v3, generate an API key, and (recommended) restrict the key to that API. Finally, it shows how to find the YouTube playlist ID from the playlist URL and notes the playlist must be public or unlisted for API access.
Guide details Spotify refresh token and YouTube API key setup for playlist automation
A two-part tutorial explains how to configure the credentials needed to automate syncing a YouTube playlist to a Spotify playlist. For Spotify, it instructs users to create a Spotify developer app on...
- A Spotify developer app is created with Web API enabled and redirect URI set to http://127.0.0.1:8888/callback.
- Users obtain Spotify Client ID and Client Secret from the app settings.
- A one-time Spotify authorization flow is used to generate a long-lived refresh_token via the /api/token endpoint.
- For YouTube, users create/select a Google Cloud project and enable the YouTube Data API v3.
- Users generate a YouTube API key in Google Cloud and restrict it to the YouTube Data API v3; the target YouTube playlist must be public or unlisted.
Spotify is sorted. Now we go to YouTube's side. The goal of this chapter is simple: get a YouTube API key and find the ID of the YouTube playlist we want to mirror. Two things. That's it. A Quick Word on the YouTube API YouTube is owned by Google, so the YouTube API lives inside Google's developer platform. Don't let that intimidate you — you're logging in with the same Google account you use for Gmail or Google Drive. Nothing new to create. The YouTube Data API has a free tier that gives you 10,000 units per day. Reading a playlist of 100 songs costs about 200 units. So unless you're syncing 50 playlists a day, you'll never hit the limit. We're well within free territory. Step 1: Go to Google Cloud Console Open your browser and go to console.cloud.google.com. Log in with your Google account. If this is your first time here, Google will ask you to agree to their Terms of Service. Accept and continue. Step 2: Create a Project Google organises everything into "projects." Think of a project as a folder for your app. We need to create one. At the very top of the page, you'll see a dropdown that probably says "Select a project." Click it, then click New Project in the top right of the popup. Give it a name — something like youtube-to-spotify works fine. Leave the organisation field as is and click Create. Google will take a few seconds to create it. Once done, make sure your new project is selected in that top dropdown before continuing. Step 3: Enable the YouTube Data API With your project selected, use the search bar at the top of the page and type "YouTube Data API v3". Click on the result that says exactly that. You'll land on an API overview page. Click the blue Enable button. After a moment, the page will refresh and show you the API is now enabled. You should see a dashboard with some quota charts — all zeros for now, which is correct. Step 4: Create an API Key Now we need an actual key. In the left sidebar, click Credentials. Then click + Create Credentials at the top and choose API key. Google will generate a key immediately and show it to you in a popup. It looks something like this: AIzaSyD3x8Kv2mNpQr7wLtYhJfUcX9vBsE1oRk Copy it. This is your API_KEY. Restrict the Key (Recommended) After copying it, click Edit API key in that same popup. Under "API restrictions," select Restrict key, then choose YouTube Data API v3 from the dropdown. Click Save. This means your key only works for YouTube — if someone somehow got hold of it, they couldn't use it anywhere else. It takes 30 seconds and it's good practice. Step 5: Find Your YouTube Playlist ID Go to youtube.com and open the playlist you want to mirror on Spotify. Look at the URL in your browser's address bar. It will look something like this: https://www.youtube.com/playlist?list=PLGBuKfnErZlAkaUUy57-mR97f8SBgMNHh The part after list= is your Playlist ID. In this example, that's PLGBuKfnErZlAkaUUy57-mR97f8SBgMNHh. That's the 70's Music Hits Playlist - Best of 70s Music Classics by Redlist Decades — the one we'll be using throughout this series. Copy that. That's all you need from YouTube. One thing to note: the playlist needs to be public or unlisted for the API to read it. If it's set to private, the script won't be able to see it. You can change the visibility in YouTube Studio under your playlist settings. What You Have Now Between Chapters 2 and 3, you've collected everything the script needs to run. Here's the full list: Variable What it is Where you got it CLIENT_ID Spotify app ID Spotify Developer Dashboard CLIENT_SECRET Spotify app secret Spotify Developer Dashboard REFRESH_TOKEN Long-lived Spotify login token curl/PowerShell command in Chapter 2 SPOTIFY_PLAYLIST_ID Your Spotify playlist to write to Spotify share link API_KEY YouTube Data API key Google Cloud Console YOUTUBE_PLAYLIST_ID PLGBuKfnErZlAkaUUy57-mR97f8SBgMNHh YouTube playlist URL Six values. That's the whole configuration. No more accounts, no more dashboards. From Chapter 4 onward, it's all code. What's Next? In Chapter 4, we write the script. We'll walk through each file — what it does, how it works, and why — in plain English. No assumed knowledge. See you there.
3 hours agoIn Chapter 1, we talked about what we're building and what accounts you need. If you've got a Spotify account, a Google account, and a GitHub account ready, you're exactly where you need to be. Today we set up Spotify. By the end of this chapter, you'll have three things: a CLIENT_ID, a CLIENT_SECRET, and a REFRESH_TOKEN. These are the keys that let our script talk to Spotify on your behalf. Let's go. Step 1: Create a Spotify Developer App Open your browser and go to developer.spotify.com. Log in with your regular Spotify account — the same one you use to listen to music. Once you're in, click on your profile name at the top right, then click Dashboard. You'll land on a page that says "My Apps" with a button that says Create app. Click it. A form appears. Fill it in like this: App name: Something descriptive. I'll use youtube-to-spotify. You can name yours whatever you like. App description: " \"Syncs a YouTube playlist to Spotify.\" One sentence is enough." Redirect URI: Type exactly this: http://127.0.0.1:8888/callback That Redirect URI looks technical, but it's just a local address on your own computer that Spotify will use during the one-time login step we'll do shortly. Copy it exactly as written. APIs used: Check the box for Web API. Accept the terms and click Save. Your app is created. You'll land on the app's settings page. Step 2: Copy Your Client ID and Client Secret On your app's settings page, you'll see two values: Client ID — visible immediately, a long string of letters and numbers Client Secret — click "View client secret" to reveal it Copy both of these somewhere safe for now — a notes app, a text file, anywhere. We'll put them in the right place in Chapter 5 when we set up our project. These two values identify your app to Spotify. The Client ID is like a username. The Client Secret is like a password. Don't share them publicly. Step 3: Get Your Refresh Token (The One-Time Login) This is the step that trips most people up, so read carefully. I promise it's not as bad as it looks. Here's why we need a Refresh Token: when our script runs automatically every day on GitHub, nobody is sitting there to log in to Spotify. The script needs a way to prove it has permission to modify your playlists without you clicking "Login" every time. The Refresh Token is that proof — a long-lived credential you get once, store safely, and the script uses forever. We get it by doing a one-time login flow. Here's how. 3a. Build the Login URL Take the URL below and replace YOUR_CLIENT_ID with your actual Client ID: https://accounts.spotify.com/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=http://127.0.0.1:8888/callback&scope=playlist-modify-public%20playlist-modify-private Paste that full URL into your browser and press Enter. Spotify will ask you to log in (if you aren't already) and then show a permissions screen asking if you want to give your app access to your playlists. Click Agree. After you click Agree, your browser will try to open a page at http://127.0.0.1:8888/callback — and it will fail with something like "This site can't be reached." That's completely fine and expected. We haven't built a server to catch that request. What we need is already in the browser's address bar. Look at the URL in your address bar. It will look like this: http://127.0.0.1:8888/callback?code=AQBvXw3Kv...a_very_long_string_here Copy everything after ?code=. That long string is your authorization code. Don't close the tab yet. 3b. Exchange the Code for a Refresh Token Now we'll swap that code for a Refresh Token using a tool called curl. If you're on Windows, open Command Prompt. On Mac or Linux, open Terminal. Run this command, replacing the three placeholder values with your own: curl -X POST https://accounts.spotify.com/api/token \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=authorization_code" \ -d "code=YOUR_AUTHORIZATION_CODE" \ -d "redirect_uri=http://127.0.0.1:8888/callback" \ -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" If curl isn't available on your Windows machine, you can use PowerShell instead: Invoke-RestMethod -Method Post -Uri "https://accounts.spotify.com/api/token" ` -Headers @{ Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("YOUR_CLIENT_ID:YOUR_CLIENT_SECRET")) } ` -Body @{ grant_type = "authorization_code" code = "YOUR_AUTHORIZATION_CODE" redirect_uri = "http://127.0.0.1:8888/callback" } Press Enter. You'll get back a block of JSON that looks like this: { "access_token": "BQA...short_lived_token", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "AQA...this_is_the_one_you_want", "scope": "playlist-modify-private playlist-modify-public" } The value next to "refresh_token" is what we're after. Copy it and keep it safe alongside your Client ID and Client Secret. The access_token expires in an hour. The refresh_token doesn't expire (unless you revoke it). Our script uses the Refresh Token to generate a fresh access token every time it runs — that's why it works unattended. Step 4: Note Your Spotify Playlist ID Remember the playlist you created in Chapter 1? We need its ID. Open Spotify, right-click on your playlist, and select Share → Copy link to playlist. You'll get a link like: https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M The part after /playlist/ is your Playlist ID. In the example above, that's 37i9dQZF1DXcBWIGoYBM5M. Copy that too. What You Have Now At the end of this chapter, you should have four things written down: What Where to find it CLIENT_ID Spotify Developer Dashboard → Your App → Settings CLIENT_SECRET Spotify Developer Dashboard → Your App → Settings REFRESH_TOKEN From the curl/PowerShell command above SPOTIFY_PLAYLIST_ID From the share link of your playlist These go into our .env file in Chapter 5. Keep them private. What's Next? In Chapter 3, we set up the YouTube side. We'll enable the YouTube Data API, grab an API key, and get the ID of the YouTube playlist we want to mirror. See you there.
1 day ago
Germany and U.S. police dismantle Kratos phishing-as-a-service; developer arrested in Indonesia
German and U.S. law enforcement dismantle the core infrastructure behind Kratos, a phishing-as-a-service (PhaaS) platfor...
D4vd preliminary hearing details decomposed body found in Tesla trunk
A Los Angeles court hears testimony and evidence at the preliminary hearing of rapper D4vd, real name David Anthony Burk...
Sunetra Pawar marks Ajit Pawar’s birth anniversary with tribute after Baramati plane crash
Maharashtra Deputy Chief Minister Sunetra Ajit Pawar pays an emotional tribute to her late husband, Ajit Pawar, on his b...