WIP save Spotify login progress
This commit is contained in:
@@ -80,7 +80,7 @@ export default function NewTripScreen({ navigation }) {
|
||||
|
||||
if (providerToken) {
|
||||
// Proactively check if token is valid, or refresh it
|
||||
console.log("Validating Spotify token...");
|
||||
console.log("Validating Spotify token via GET /v1/me...");
|
||||
let testRes = await fetch('https://api.spotify.com/v1/me', {
|
||||
headers: { Authorization: `Bearer ${providerToken}` }
|
||||
});
|
||||
@@ -90,19 +90,17 @@ export default function NewTripScreen({ navigation }) {
|
||||
const newToken = await refreshSpotifyToken();
|
||||
if (newToken) {
|
||||
providerToken = newToken;
|
||||
console.log("Spotify token refreshed successfully!");
|
||||
} else {
|
||||
console.log("Failed to refresh Spotify token.");
|
||||
providerToken = null;
|
||||
}
|
||||
} else if (!testRes.ok) {
|
||||
const testErr = await testRes.text();
|
||||
if (testRes.status === 403 || testErr.toLowerCase().includes('active premium subscription required')) {
|
||||
spotifyPremiumRequired = true;
|
||||
console.warn("Spotify validation skipped due to expected Premium limitation:", testRes.status, testErr);
|
||||
} else {
|
||||
console.warn("Spotify validation request failed:", testRes.status, testErr);
|
||||
}
|
||||
console.warn("Spotify validation request failed on GET /v1/me:", testRes.status, testErr);
|
||||
providerToken = null;
|
||||
} else {
|
||||
console.log("Spotify token is valid (GET /v1/me returned 200 OK).");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +152,10 @@ export default function NewTripScreen({ navigation }) {
|
||||
}
|
||||
|
||||
// D. Create empty playlist
|
||||
console.log("[SpotifyPlaylistDebug] playlist create request started");
|
||||
console.log("[SpotifyPlaylistDebug] userId exists:", Boolean(spotifyUserId));
|
||||
console.log("[SpotifyPlaylistDebug] access token exists:", Boolean(providerToken));
|
||||
|
||||
const createPlaylistRes = await fetch(`https://api.spotify.com/v1/users/${spotifyUserId}/playlists`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -166,7 +168,21 @@ export default function NewTripScreen({ navigation }) {
|
||||
public: false
|
||||
})
|
||||
});
|
||||
const playlistData = await safeParseJson(createPlaylistRes, 'CreatePlaylist');
|
||||
|
||||
console.log("[SpotifyPlaylistDebug] create playlist HTTP status:", createPlaylistRes.status);
|
||||
const createPlaylistResText = await createPlaylistRes.text();
|
||||
if (!createPlaylistRes.ok) {
|
||||
console.log("[SpotifyPlaylistDebug] create playlist response body if failed:", createPlaylistResText);
|
||||
throw new Error(`Spotify API returned status ${createPlaylistRes.status} for CreatePlaylist: ${createPlaylistResText.substring(0, 150)}`);
|
||||
}
|
||||
|
||||
let playlistData: any;
|
||||
try {
|
||||
playlistData = JSON.parse(createPlaylistResText);
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to parse JSON response for CreatePlaylist: ${createPlaylistResText.substring(0, 150)}`);
|
||||
}
|
||||
|
||||
if (!playlistData.id) throw new Error('Could not create playlist');
|
||||
const playlistId = playlistData.id;
|
||||
generatedPlaylistUrl = playlistData.external_urls.spotify;
|
||||
@@ -225,6 +241,8 @@ export default function NewTripScreen({ navigation }) {
|
||||
const chunkSize = 100;
|
||||
for (let i = 0; i < trackUris.length; i += chunkSize) {
|
||||
const chunk = trackUris.slice(i, i + chunkSize);
|
||||
|
||||
console.log("[SpotifyPlaylistDebug] Add tracks request started for chunk:", i / chunkSize + 1);
|
||||
const addTracksRes = await fetch(`https://api.spotify.com/v1/playlists/${playlistId}/tracks`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -233,8 +251,11 @@ export default function NewTripScreen({ navigation }) {
|
||||
},
|
||||
body: JSON.stringify({ uris: chunk })
|
||||
});
|
||||
|
||||
console.log("[SpotifyPlaylistDebug] add tracks HTTP status:", addTracksRes.status);
|
||||
if (!addTracksRes.ok) {
|
||||
const addTracksErr = await addTracksRes.text();
|
||||
console.log("[SpotifyPlaylistDebug] add tracks response body if failed:", addTracksErr);
|
||||
if (addTracksRes.status === 403 || addTracksErr.toLowerCase().includes('active premium subscription required')) {
|
||||
spotifyPremiumRequired = true;
|
||||
console.warn("Spotify add tracks skipped due to expected Premium limitation:", addTracksRes.status, addTracksErr);
|
||||
|
||||
Reference in New Issue
Block a user