mirror of
https://github.com/jwilsson/spotify-web-api-php.git
synced 2026-04-26 23:45:49 +03:00
[GH-ISSUE #194] Update Playlist Image Bad Request #130
Labels
No labels
bug
docs
enhancement
enhancement
enhancement
feedback wanted
good first issue
help wanted
help wanted
help wanted
invalid
pull-request
question
question
upstream
upstream
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotify-web-api-php#130
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @MadalenaSousa on GitHub (May 17, 2020).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/194
Hi there!
I'm trying to make an image the cover of a playlist and I keep getting a Bad Request error.
The picture is base64 encoded, a jpeg, I've reduced it to 0.01 of it's original size and the permissions are the ones refered on the spotify api website.
Any ideia on what this error could be?
Here is the full error:
Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: Bad request. in ...\vendor\jwilsson\spotify-web-api-php\src\Request.php:45 Stack trace: #0 ..\vendor\jwilsson\spotify-web-api-php\src\Request.php(254): SpotifyWebAPI\Request->parseBody(Object(stdClass), 400) #1 ..\vendor\jwilsson\spotify-web-api-php\src\Request.php(126): SpotifyWebAPI\Request->send('PUT', 'https://api.spo...', 'ZGF0YTppbWFnZS9...', Array) #2..\vendor\jwilsson\spotify-web-api-php\src\SpotifyWebAPI.php(76): SpotifyWebAPI\Request->api('PUT', '/v1/playlists/1...', 'ZGF0YTppbWFnZS9...', Array) #3 ...\vendor\jwilsson\spotify-web-api-php\src\SpotifyWebAPI.php(1705): SpotifyWebAPI\SpotifyWebAPI->sendRequest('PUT', '/v1/playlists/1...', 'ZGF0YTppbWFnZS9...') #4 ..\php\createPlaylist.php(23): SpotifyWebAPI\SpotifyWebAPI->updatePlaylistImage('1UJzLOz61XQJV7Z...', 'ZGF0YTppbWFnZS9...') #5 {main} thrown in ..\vendor\jwilsson\spotify-web-api-php\src\Request.php on line 45
@jwilsson commented on GitHub (May 17, 2020):
Hey!
That's strange. It's working when I try it.
Could you share the code you're using? And have you tried with another playlist and/or image?
@MadalenaSousa commented on GitHub (May 17, 2020):
Sure! I'll try share the important parts:
I have a form that runs this php code:
$playlistName = $_POST['playlistname']; //creates playlist
$newPlaylist = $api->createPlaylist([
'name' => $playlistName
]);
$songTotal = $_POST['songTotal']; //add songs
for($i = 0; $i < $songTotal; $i++) {
$api->addPlaylistTracks($newPlaylist->id, [
$_POST['songId' . $i]
]);
}
if($_POST['cover'] == 'use') { //define cover
$imageData = base64_encode($_POST['playlistImg']);
$api->updatePlaylistImage($newPlaylist->id, $imageData);
}
Then the image that I want to use is the canvas, converted to jpg:
let canvas = document.getElementById('defaultCanvas0');
let img = new Image(200, 200);
img.src = canvas.toDataURL('image/jpeg', 0.01); //this defines the format and the quality
document.querySelector('.preview').appendChild(img);
Since this all happens in a pop up, I'm creating the input with the image data:
let playlistImg = document.createElement('input');
playlistImg.setAttribute('type', 'hidden');
playlistImg.setAttribute('name', 'playlistImg');
playlistImg.setAttribute('value', img.src);
document.querySelector('.create-playlist form').appendChild(playlistImg);
I've checked if the base64 encoding is right, and it seems to be.
Thank you for the quick response
@MadalenaSousa commented on GitHub (May 17, 2020):
All right, I tryed with another image like you said and it works. It's my mistake, I'll figure it out, thank you for your help!