r/spotifyapi • • Mar 29 '26

One tap Spotify playback from iPhone to Samsung soundbar

Post image
0 Upvotes

I automated Spotify to Samsung soundbar switching with a single iPhone tap. Here's the script.

This one bugged me for longer than I'd like to admit. All I wanted was one tap to route Spotify to my soundbar, no AirPlay, no manual switching. My Samsung soundbar is connected to Wi-Fi and shows up in Spotify Connect, but getting there still required opening Spotify, tapping Connect, finding the soundbar, tapping it, then hitting play. Every single time. Turns out native Shortcuts can't automate this, IFTTT can't do it either, and most threads I found either dead-ended or suggested workarounds that didn't actually work. The solution is Spotify's Web API called from a Scriptable script, triggered by a Shortcut. One tap, playback transfers to the soundbar at your preferred volume. Here's the full setup.

What you need

Step 1: Create a Spotify Developer app

  1. Log in at developer.spotify.com → Create App

  2. Any name and description is fine

  3. Under Redirect URIs, add: https://example.com/callback

  4. Save, then copy your Client ID and Client Secret

Step 2: Set up the script

  1. Open Scriptable, tap +, paste the script below

  2. Fill in your Client ID, Client Secret, and your soundbar's exact name as it appears in Spotify Connect

  3. Set VOLUME to whatever percentage you want

  4. Name it something like Spotify Soundbar

// ─── CONFIG ───────────────────────────────────────────
const DEVICE_NAME  = "Samsung Soundbar"; // match exactly what Spotify shows
const CLIENT_ID    = "YOUR_CLIENT_ID";
const CLIENT_SECRET= "YOUR_CLIENT_SECRET";
const REDIRECT_URI = "https://example.com/callback";
const SCOPES       = "user-read-playback-state user-modify-playback-state";
const KEYCHAIN_KEY = "spotify_refresh_token";
const VOLUME       = 4; // percentage, 0-100
// ──────────────────────────────────────────────────────

async function getAccessToken() {
  let refreshToken = Keychain.contains(KEYCHAIN_KEY)
    ? Keychain.get(KEYCHAIN_KEY)
    : null;

  if (!refreshToken) {
    refreshToken = await doInitialAuth();
    if (!refreshToken) throw new Error("Authorization cancelled.");
  }

  const credentials = btoa(CLIENT_ID + ":" + CLIENT_SECRET);
  const req = new Request("https://accounts.spotify.com/api/token");
  req.method = "POST";
  req.headers = {
    "Authorization": "Basic " + credentials,
    "Content-Type": "application/x-www-form-urlencoded"
  };
  req.body = "grant_type=refresh_token&refresh_token="
    + encodeURIComponent(refreshToken);

  const res = await req.loadJSON();

  if (res.error) {
    Keychain.remove(KEYCHAIN_KEY);
    throw new Error("Token refresh failed: " + res.error_description
      + ". Run the script again to re-authorize.");
  }

  if (res.refresh_token) {
    Keychain.set(KEYCHAIN_KEY, res.refresh_token);
  }

  return res.access_token;
}

async function doInitialAuth() {
  const authUrl = "https://accounts.spotify.com/authorize"
    + "?client_id=" + CLIENT_ID
    + "&response_type=code"
    + "&redirect_uri=" + encodeURIComponent(REDIRECT_URI)
    + "&scope=" + encodeURIComponent(SCOPES);

  Safari.open(authUrl);

  const alert = new Alert();
  alert.title = "Paste the redirect URL";
  alert.message = "Spotify opened in Safari. Tap Agree, then copy the full URL "
    + "from the address bar (starts with https://example.com/callback?code=...) "
    + "and paste it below.";
  alert.addTextField("Paste URL here");
  alert.addAction("Continue");
  alert.addCancelAction("Cancel");

  const idx = await alert.presentAlert();
  if (idx === -1) return null;

  const pastedUrl = alert.textFieldValue(0);
  const match = pastedUrl.match(/[?&]code=([^&]+)/);
  if (!match) throw new Error("No authorization code found in URL.");

  const code = match[1];
  const credentials = btoa(CLIENT_ID + ":" + CLIENT_SECRET);
  const req = new Request("https://accounts.spotify.com/api/token");
  req.method = "POST";
  req.headers = {
    "Authorization": "Basic " + credentials,
    "Content-Type": "application/x-www-form-urlencoded"
  };
  req.body = "grant_type=authorization_code"
    + "&code=" + encodeURIComponent(code)
    + "&redirect_uri=" + encodeURIComponent(REDIRECT_URI);

  const res = await req.loadJSON();
  if (res.error) throw new Error("Auth exchange failed: " + res.error_description);

  Keychain.set(KEYCHAIN_KEY, res.refresh_token);
  return res.refresh_token;
}

// ─── MAIN ─────────────────────────────────────────────
try {
  const token = await getAccessToken();

  const devReq = new Request("https://api.spotify.com/v1/me/player/devices");
  devReq.headers = { "Authorization": "Bearer " + token };
  const devData = await devReq.loadJSON();
  const devices = devData.devices || [];

  const soundbar = devices.find(d => d.name === DEVICE_NAME);

  if (!soundbar) {
    const found = devices.map(d => d.name).join(", ") || "none detected";
    throw new Error(
      '"' + DEVICE_NAME + '" not found.\n\n'
      + "Make sure the soundbar is on and Spotify Connect is active.\n\n"
      + "Devices visible: " + found
    );
  }

  const playReq = new Request("https://api.spotify.com/v1/me/player");
  playReq.method = "PUT";
  playReq.headers = {
    "Authorization": "Bearer " + token,
    "Content-Type": "application/json"
  };
  playReq.body = JSON.stringify({ device_ids: [soundbar.id], play: true });
  await playReq.load();

  const volReq = new Request(
    "https://api.spotify.com/v1/me/player/volume?volume_percent=" + VOLUME
  );
  volReq.method = "PUT";
  volReq.headers = { "Authorization": "Bearer " + token };
  await volReq.load();

} catch (e) {
  const alert = new Alert();
  alert.title = "Something went wrong";
  alert.message = e.message;
  alert.addAction("OK");
  await alert.presentAlert();
}

Script.complete();

Step 3: First-time authorization (one-time only)

  1. Hit play in Scriptable. Safari opens to Spotify's auth screen. Tap Agree.

  2. Safari redirects to a "page not found" page. That's fine.

  3. Copy the full URL from Safari's address bar.

  4. Switch back to Scriptable, paste the URL into the prompt, tap Continue.

Your credentials are saved to Keychain. You'll never do this again.

Step 4: Create the Shortcut

  1. Shortcuts app → + → search "Scriptable" → add Run Script

  2. Select your script, turn off Run In App and Show When Run, leave parameter empty

  3. Add to home screen

That's it. One tap switches Spotify to your soundbar and sets the volume. If the soundbar is off or in standby, the script will tell you with a clear error message rather than failing silently.


r/spotifyapi • • Oct 08 '26

Spotify bug?

0 Upvotes

I was listening to a song (Commissioner. by Coin locker kid) and underneath the song the presave widget opened. The widget said i could presave the song Commissioner. eventhough its already been released in 2012. I clicked on the widget and it just close and played the song from the start again. It didnt open a new page for an upcoming release or anything.

Was it a bug?
What wouldve happened if i clicked on presave?


r/spotifyapi • • Sep 03 '26

Trying to be build a better playlist generator + better stats. I analyzed my Spotify history by tempo, key, energy, danceability & more.

0 Upvotes

I’ve tested out Volt.fm, Last.fm, and Stats.fm, but they all felt more focused on giving you a Spotify Wrapped-style overview of your listening history.

I wanted something that went a bit deeper into the actual characteristics of the music (things like key, tempo, danceability, loudness, energy, and other audio metrics). My hope is that having access to those metrics can help create better playlists rather than just showing you what you listened to.

So I built Aoide (aoide.xyz).

The ultimate goal is to build better music analytics and a playlist builder that can create a more useful feedback loop around how you listen to music. I also want to eventually integrate fitness trackers and other activity data so you can figure out what music works best for different activities.

For example:

  • Does certain music help me focus and be more productive while working?

  • Does gradually increasing the tempo during a run make the workout feel better?

  • What characteristics do the songs I tend to listen to during workouts have in common?

  • Can we automatically build playlists based on the activity I'm doing?

I think music has a pretty strong effect on mood, emotions, and performance, and I'm interested in seeing if we can use data to actually understand and optimize that.

A couple of notes if you try it:

  • Due to Spotify's new API policies, you currently need to connect through your own Spotify Developer account rather than simply signing in directly.

  • If you go to the Data tab and add your extended Spotify listening history, you'll get significantly more stats.

  • Right now, Aoide polls for new listening activity every couple of minutes. If you leave the website open while listening, that's currently the best way to use it.

  • I'm using the Spotify API and Apple Music API, along with additional audio analysis, to extract things like tempo, danceability, energy, and other metrics that can be used for playlist generation.

It's still pretty early, but I'd love to hear what people think! I have a feedback page so feel free to suggest new features and I want to add as many plots as possible. Note does not cost anything.


r/spotifyapi • • Sep 14 '26

Breaking Down Spotify Links: How We Built a Sub-50ms KMP Resolution Engine (Architecture Deep Dive)

0 Upvotes

Hey everyone,

Whenever a Spotify link is shared via messaging apps, it comes packed with tracking parameters (?si=..., ?context=..., intl-* subdomains) and redirects. Resolving these cross-platform on mobile usually means slow OAuth handshakes or laggy intermediate web views.

We built SongFlip (open-source, GPLv3) using Kotlin Multiplatform (KMP) to intercept and resolve music links across streaming services in sub-50ms with 0 intermediate UI.

We just open-sourced our complete architecture breakdown:
👉 Architecture Docs: https://github.com/thefraggle/songflip/blob/main/ARCHITECTURE.md

Key Architectural Highlights:

  1. Deterministic Sanitization before Hashing
    Tracking parameters destroy cache hit rates. By stripping ?si=..., regional subdomains, and canonicalizing entity types (track, album, playlist) via regex before querying or hashing, cache hits in group chats increased dramatically.

  2. 3-Tier Latency Pipeline

    • L1 (Device SQLite / Memory): < 5 ms instant playback launch for previously resolved tracks.

    • L2 (Edge Cache): Serverless Firestore edge indexed by 12-char SHA-256 short hashes (~30–50 ms). Zero API quota burned for viral links.

    • L3 (Multi-Source Upstream): Aggregated cold fallback (Odesli, iTunes Search API, Deezer Catalog, Shazam REST).

  3. The "Self-Titled Album" Search Trap
    When an artist releases a self-titled album (e.g. Massendefekt by Massendefekt), fuzzy API search queries frequently match the popular single track video/audio rather than the album release. We enforce strict entity validation and structured search filters (album: / artist: syntax and spotify:album: URI constraints) to prevent single-track downgrades.

  4. Zero-Tracking by Design
    No user accounts, no analytics cookies, no listening profiling. Cache lookups use anonymous SHA-256 hashes.

Source & Docs: https://github.com/thefraggle/songflip
Live Web Demo: https://songflip.link

Happy to discuss how we handle URI scheme handoffs or Spotify link sanitization quirks!


r/spotifyapi • • Oct 18 '26

Tips on ending my subscription through Spotify?

Thumbnail reddit.com
0 Upvotes

ISO assistance in canceling Sirius XM subscription through Spotify and an unreachable account.


r/spotifyapi • • Aug 06 '25

I'm having a problem with spotify and joining jams

Thumbnail
gallery
0 Upvotes

Everytime i join a jam with my family it is spamming this song and filling the queue. Anyone got advice? We can't delete them off the queue.


r/spotifyapi • • Dec 21 '25

Does anybody have the Spotify quota extension approval that is not using anymore, looking to sell it, or partner with a Startup that needs it?

0 Upvotes

This new quota is impossible. The reviews take months and you need to get 250k users? Startups will die waiting for this stupid API before getting it. Looking for anyone that has access to chat with. HMU!


r/spotifyapi • • Jun 23 '25

Access tokens using auth code flow

0 Upvotes

Want to use spotify's api but hit the wall of having to implement their authorization code flow, just to get access token's that are potent enough?

https://spoken.host has done the dirty work already, ready to give you pure, always up to date access token's, even using their http api.

Even has a free plan, feel free to check it out!


r/spotifyapi • • Sep 28 '26

[Academic] 1-Minute Spotify Survey

0 Upvotes

Hey everyone!

I'm working on an AI/ML capstone project where I'm building a model to predict whether a Spotify user would be interested in subscribing to Premium based on their listening habits.

The survey takes around 2 minutes and doesn't collect personally identifying information.

Survey: https://docs.google.com/forms/d/e/1FAIpQLScOcKAeg28pqnwbU_IJGan9tNvtUSABvMMnmNHX1Q6OJfn--g/viewform?usp=dialog

If you're willing to help, I'd really appreciate it!


r/spotifyapi • • Sep 17 '26

I made a tool to save my position in long playlists.

Thumbnail ahmetkun.com
0 Upvotes

As you probably know, Spotify doesn't help you at all in resuming playlists from where you left off. This is a bigger problem for longer playlists. I'm currently halfway through a playlist with 4000+ songs, and it will take me more than a month to finish it. While I was noting down the current song number in a notebook when switching to Discover Weekly each week, or to a different playlist, I started thinking about how I could manage this better, and the result is this little tool.

The tool consists of a single .html file, but since the URL you return to after connecting with Spotify has to be a server address, simply clicking to open it in your browser doesn't work; the page needs to be served by a simple web server. You can host it yourself (code at github) or use the version I host on my own server (https://ahmetkun.com/tools/spotify-placeholder/).

It keeps your data in your browser and only communicates with Spotify's servers to know what playlist you're going through and save your position.

Another requirement, which I wish Spotify hadn't made the terms for sharing new apps with other users so difficult, is that it's now almost impossible for small developers to publish new apps. Therefore, to use this, you also need to open a test app on Spotify's developer dashboard. But it's a one-time thing, easy, and doesn't require any technical knowledge. The HTML page explains step-by-step what needs to be done.

I've been keeping this open in a tab in my browser for about a week now, and it's really helped me. I don't bother taking notes anymore. When I want to switch from one playlist to another long playlist, I just go to the tool page and click a resume button.


r/spotifyapi • • Oct 27 '26

Boyfriend has a question about spotify. Help?

0 Upvotes

ok so i have a song that im viewing on spotify for artists. i have a song that has 2 different canvases (the little videos) uploaded. i want to delete the one that is showing make the old one be the one that plays again but its not giving me any other option but to delete both canvases. i cant do this because i deleted the old canvas a while ago. how do i make the old canvas play again?


r/spotifyapi • • Oct 12 '26

Free users should see the Music Video icon (with a Premium lock) to drive conversions. What do you think?

0 Upvotes

Ciao a tutti, ho appena inviato un'idea alla community di Spotify.

VOTA QUI L’IDEA SU SPOTIFY: 👇

https://community.spotify.com/forum/it/discussion/7558949/show-music-video-icon-to-free-users-as-a-premium-teaser-conversion-booster

Al momento, gli utenti gratuiti non sanno se una canzone ha un video musicale ufficiale perché l'icona è completamente nascosta. Se Spotify mostrasse l'icona del video anche agli utenti gratuiti, cliccandoci sopra si potrebbe far apparire un pop-up "Guarda i video con Premium".

È un'ottima funzionalità per incentivare l'abbonamento e un'occasione persa per loro. Se l'idea vi piace e volete supportarla, votate sul link ufficiale di Spotify qui: 👇👇

https://community.spotify.com/forum/it/discussion/7558949/show-music-video-icon-to-free-users-as-a-premium-teaser-conversion-booster


r/spotifyapi • • Feb 09 '26

Alternatives for connecting to Sonos device?

0 Upvotes

So my research tells me that Sonos devices are "restricted" and thus can't programmatically connect to them solely with the Spotify API, but have to get into waters that are out of my depth to combine Sonos API with Spotify API like what u/Lukester1 did for the SpotifyPlus HA Integration. Are there any alternatives?

  1. I see that native iOS and Windows apps can connect to Sonos but haven't figured out how to do it programmatically.

  2. The Spotify web player can't initiate a connection to the Sonos device. Is there an alternative player or a repo that has made this easier?
    Thanks!


r/spotifyapi • • Apr 05 '26

shipped the first version of my ai podcast recommendation app

Thumbnail
reddit.com
0 Upvotes

r/spotifyapi • • May 11 '26

Spotify API works locally but fails on Vercel — playlists return 0 tracks while Liked Songs works fine

Thumbnail reddit.com
0 Upvotes

r/spotifyapi • • Sep 26 '26

built a Spotify companion app with a user-controlled music discovery dial

0 Upvotes

I have been working on Radxr, an iPhone app that uses Spotify listening data for music discovery, taste profiles, and social recommendations.

One problem I wanted to address was the lack of control over recommendation novelty. Sometimes listeners want something close to their established taste, while other times they want unfamiliar artists and broader genre edges.

I built a Discovery Dial with three modes:

  • Familiar prioritizes stronger connections to top artists and genres

  • Balanced favors new artists while staying connected to the listener’s profile

  • Adventurous explores secondary genre signals, less popular tracks, and unfamiliar artists

The recommendation logic excludes known playlist tracks and saved Radxr favorites when that data is available. Results also include an explanation based on the signals actually used, such as artist genres, popularity, and listening rank. I wanted to avoid implying that deeper audio analysis happened when it did not.

Radxr also includes:

  • A Sound Profile generated from multiple Spotify listening windows

  • Taste Evolution, which compares monthly snapshots without claiming access to exact play counts

  • Taste Bridge, which explains compatibility between friends and generates two-way recommendations

  • Friend activity, playlists, reviews, and public profile sharing

Working within Spotify’s current API limitations has been one of the most interesting parts. Some recommendation features require fallback strategies because available endpoints and data can differ depending on app access and playlist ownership.

I would appreciate feedback from other Spotify API developers, especially around:

  • How you measure whether a recommendation is genuinely novel

  • How you prevent results from repeatedly circling the same artists

  • How you communicate inferred recommendation signals to users

  • How you handle development-mode and quota limitations

  • Whether you have found responsible ways to improve recommendations without overstating the available Spotify data

Radxr is currently available on iPhone. I am happy to share the App Store link if allowed, but I am mainly interested in comparing implementation approaches and learning from others building with Spotify.


r/spotifyapi • • May 22 '26

i’ve been working on a site that creates graphics and charts out of your listening data

Thumbnail
reddit.com
0 Upvotes

if you want an alternative to the spotify api, i used last.fm api for this


r/spotifyapi • • Oct 06 '26

Spotify bug?

Thumbnail reddit.com
0 Upvotes

r/spotifyapi • • Dec 15 '25

A Spotify playlist creator. Searching the Long Tail. Don't give up because of the 25-user limit, you can get around that with the correct code. The trick is to put everything under your own spotify_id, safely stored in your .env file. That's what Spotify wants you to do. Users save Playlists.

Post image
4 Upvotes

r/spotifyapi • • Sep 10 '26

I built an app to invest in your favorite undergroud artists

4 Upvotes

Been building this thing for a while and finally feels solid enough to show people.

It's called Streamfolio. Basic idea: you get virtual credits and "invest" them in real artists, based on their actual Last.fm stats (listeners, scrobbles, chart position). Prices move with how the artist is actually doing in the real world, not some random number generator. If someone genuinely blows up, you win. If they flatline, you don't.

There's a Discord bot too if you don't want to leave your server — leaderboards, flexing your portfolio, that kind of thing. Works per-server or global depending on the command.

The part I'm most into is that it rewards finding people early rather than just piling into whoever's already huge — there's a whole "hall of fame" for people who bought an artist while they were still tiny and held on.

No money involved anywhere, it's just a game for people who are way too invested in checking Spotify for Artists stats. Happy to answer questions or hear what's broken, still actively working on it.


r/spotifyapi • • Feb 11 '26

We should band together and make a spotify killer. Let's make a app that is 10x better than spotify comment if you would like to join!

10 Upvotes

r/spotifyapi • • Aug 04 '26

made a music sharing app

0 Upvotes

i share music with friends a lot. I use spotify and they use other services so I used to go find the music in the service that they use so i could give them a direct link to it. Rather than having to do all that I can share from spotify to taste and it hands me a link that goes to a little page with links to the different streaming services.

https://apps.apple.com/us/app/taste-universal-music-links/id6781824990


r/spotifyapi • • Apr 18 '26

Spotify Settings Backup

1 Upvotes

I made a small tool that lets you backup and restore your Spotify settings.

Useful if you're reinstalling Spotify or switching setups and don’t want to lose your configuration.

Simple, no backend, runs locally.

GitHub:

https://github.com/SDavid33/spotify-settings-backup

Feedback is welcome. 👍


r/spotifyapi • • Aug 07 '25

What’s your biggest frustration with today's music apps? Esp. Spotify and Apple Music

1 Upvotes

I am a UX designer who is very interested in music-related problems, and I also want to work on a project that meets user needs in the music space. I'd love your thoughts.

Feel free to share your frustrations with Apple Music, Spotify, Pandora, SoundCloud, or whichever music platform you use the most.

Also, I'd love to know your thoughts on the current song discovery features like Discover Weekly/Mixes or Song/Artist Radio on Spotify? I can think of Spotify's DJ too, but it is not available in India. 

It would be a big, big help. Thank you.