Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Can't create playlist for own user.

Can't create playlist for own user.

Hi,

 

I can't create a playlist for my own user

https://developer.spotify.com/documentation/web-api/tutorials/getting-started#request-artist-data

 

I always get 

“status”: 403, “message”: “You cannot create a playlist for another user”

 

I can do other things, like get artist info.

I got the user ID from the profile page and it also what I get back from the PKCE example: https://github.com/spotify/web-api-examples/tree/master/authorization/authorization_code_pkce

 

This is my example code:

 

 

 

 

 

 

 

<?php

/* GET AUTHORIZATION */

$post = [
    'grant_type' => 'client_credentials',
    'scope' => 'playlist-modify-public playlist-modify-private',
];
$ch = curl_init('https://accounts.spotify.com/api/token');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/x-www-form-urlencoded',
    'Authorization: Basic ' . base64_encode('{CLIENT_ID}:{CLIENT_SECRET}'),
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( $post ) );


$response = curl_exec($ch);
curl_close($ch);

$response = json_decode( $response, 1 );




/* ADD PLAYLIST */

$ch = curl_init('https://api.spotify.com/v1/users/{USER_ID}/playlists');

$playlist = json_encode( array( 'name' => 'Pandafish Test', 'description' => 'Testing the API', 'public' => 'true' ) );

curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type:application/json',
    'Authorization: Bearer ' . $response[ 'access_token' ],
]);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $playlist );

$playlist = curl_exec($ch);

curl_close($ch);

 

 

 

 

 

 

 

Thanks for having a look.

 

Kind regards,

 

Stijn

 

Reply
9 Replies

It looks like you are trying to mix Client Credentials with the the PKCE flow.

I recommend you to start over and only use code from that flow.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Hi Ximzend.

 

Thanks for replying, but I think you misunderstand. I'm not using PKCE, only the code in my example.

 

I was just using the PKCE workflow from Github to see if the user ID I got from the profile page was the correct one to use for creating a play list.

 

 

 

 

Screenshot 2024-04-30 at 21.17.41.png

hi Stijn,

 

Then there is the problem: you can't access user data like this with Client Credentials.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Hi Ximzend,

 

not even your own playlist? The Web app is created specifically with this user.

 

 

Hi Stijn,

 

You don't log in with Client Credentials, so the generated token is never linked to an account. Therefore you can't get your own playlists that are not publicly displayed at your profile.

 

Cheers,

Vincent

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Additionally, you can get your publicly displayed playlists with Client Credentials without the need of using Authorization Scopes.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Hi Vincent,

 

first of, thanks for the help so far.

 

I'm actually (public) trying to create a playlist.

 

Just to be sure: I am using the credentials in the actual code, I am just replacing them with {CLIENT_ID} etc. in my example above.

 

I am using the authorization flow from the example here: https://developer.spotify.com/documentation/web-api/tutorials/getting-started#request-an-access-toke...

 

That is Client Credentials flow, right?

 

What would I have to change to the authorization to be able to publish public playlists on my own profile?

 

Thanks.

 

 

Hi Stijn,

 

The first tutorial uses indeed Client Credentials.

Client Credentials are not linked to any account, so to create a playlist for you or another user, Authorization is required.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Yes. I got it working!

 

Like Ximzend said, you need to use the Authorization flow to be able to edit playlists: https://developer.spotify.com/documentation/web-api/tutorials/code-flow

 

This Stack Overflow question also helped me a lot: 

Suggested posts

Type a product name