We build custom applications 5x faster and cheaper 🚀
Book a Free Consultation
Stuck on an error? Book a 30-minute call with an engineer and get a direct fix + next steps. No pressure, no commitment.
High-level: Build a small external service that handles the Spotify OAuth (authorization code) flow, stores user refresh tokens securely, and exposes a simple authenticated REST surface your OpenClaw skill calls. The skill (installed via your OpenClaw/ClawHub workflow) should forward intent parameters (play, pause, play track/URI, seek, get current track) to that service; the service makes the real Spotify Web API calls (PUT /v1/me/player/play, PUT /v1/me/player/pause, GET /v1/me/player/currently-playing) using fresh access tokens. Keep long-lived state and token refresh outside the agent runtime, require Spotify Premium for playback control, request correct scopes, and debug by checking OAuth token exchanges, API responses, and logs.
https://accounts.spotify.com/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_REDIRECT_URI&scope=user-modify-playback-state%20user-read-playback-state%20user-read-currently-playing&state=RANDOM_STATE
POST https://accounts.spotify.com/api/token
Content-Type: application/x-www-form-urlencoded
Authorization: Basic BASE64(client_id:client_secret)
grant_type=authorization_code&code=CODE_FROM_QUERY&redirect_uri=YOUR_REDIRECT\_URI
Response will include access_token, token_type, expires_in, refresh_token (store this).
POST https://accounts.spotify.com/api/token
Content-Type: application/x-www-form-urlencoded
Authorization: Basic BASE64(client_id:client_secret)
grant_type=refresh_token&refresh_token=USER_REFRESH\_TOKEN
PUT https://api.spotify.com/v1/me/player/play?device_id=DEVICE_ID
Authorization: Bearer ACCESS\_TOKEN
Content-Type: application/json
{
"uris": ["spotify:track:TRACK\_ID"],
"position\_ms": 0
}
PUT https://api.spotify.com/v1/me/player/pause?device_id=DEVICE_ID
Authorization: Bearer ACCESS\_TOKEN
GET https://api.spotify.com/v1/me/player/currently-playing
Authorization: Bearer ACCESS\_TOKEN
// Exchange authorization code for tokens
curl -X POST https://accounts.spotify.com/api/token \\
-H "Authorization: Basic BASE64(client_id:client_secret)" \\
-H "Content-Type: application/x-www-form-urlencoded" \\
-d "grant_type=authorization_code&code=AUTH_CODE&redirect_uri=YOUR_REDIRECT_URI"
// Start playback on a user's device
const fetch = require('node-fetch');
async function playTrack(accessToken, deviceId, trackUri) {
const url = 'https://api.spotify.com/v1/me/player/play' + (deviceId ? `?device_id=${encodeURIComponent(deviceId)}` : '');
const body = JSON.stringify({ uris: [trackUri] });
const res = await fetch(url, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
body,
});
if (!res.ok) {
const text = await res.text();
throw new Error(`Spotify play failed: ${res.status} ${text}`);
}
}
Speak one‑on‑one with a senior engineer about your no‑code app, migration goals, and budget. In just half an hour you’ll leave with clear, actionable next steps—no strings attached.
1
Implement an AuthAdapter that stores refresh tokens outside the agent (DB or secrets store), reads client_id/secret from environment variables, exchanges refresh tokens at the provider token endpoint, updates stored tokens, and returns a valid access_token to skills before each call.
Keep tokens stateful outside the runtime, refresh proactively, and fail-safe if refresh fails.
2
Use a PlaybackAdapter to translate Claw skill commands into concrete device API calls, and expose a secure ClawEndpoint webhook that authenticates requests, validates webhooks, routes commands to the adapter, and returns execution status. Keep credentials in env vars, persist device state outside the agent runtime, and rely on logs + API response inspection for debugging.
Key steps:
// PlaybackAdapter maps high-level commands to device REST calls
class PlaybackAdapter {
constructor(token){ this.token = token }
async play(deviceId, url){
// call device API
return fetch(`https://api.device/${deviceId}/play`, { method:'POST', headers:{ Authorization:`Bearer ${this.token}` }, body: JSON.stringify({ url }) })
}
}
// ClawEndpoint: express webhook verifies signature then routes to adapter
3
Fix stuttering by increasing the audio sink's buffer/jitter buffer, pre-buffering more frames, matching sample rates, and moving tight audio processing out of the agent runtime to a dedicated worker or external service; use environment variables to tune buffer sizes and enable verbose audio logs to measure underruns.
Start by collecting logs and CPU/GC metrics from the OpenClaw agent runtime.
4
Direct answer: Map EventBus event types (play, pause, stop, seek, buffer-start, buffer-end, error) to the nearest ClawPlaybackState (PLAYING, PAUSED, STOPPED, SEEKING, BUFFERING, ERROR). Treat events as authoritative only after validation, apply idempotency and ordering, and publish resulting ClawPlaybackState back on the EventBus.
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
From startups to enterprises and everything in between, see for yourself our incredible impact.
Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.Â