Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for playlist.add_tracks! if no credentials for the playlist owner exist #262

Conversation

shaicoleman
Copy link
Contributor

@shaicoleman shaicoleman commented May 3, 2024

Calling add_tracks! causes the following exception:

/home/shai/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/rspotify-2.12.1/lib/rspotify/user.rb:65:in `oauth_header': undefined method `[]' for nil (NoMethodError)

        'Authorization' => "Bearer #{@@users_credentials[user_id]['token']}",
                                                                 ^^^^^^^^^
	from /home/shai/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/rspotify-2.12.1/lib/rspotify/user.rb:73:in `oauth_send'
	from /home/shai/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/rspotify-2.12.1/lib/rspotify/user.rb:87:in `block (2 levels) in <class:User>'
	from /home/shai/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/rspotify-2.12.1/lib/rspotify/playlist.rb:165:in `add_tracks!'	

This is because the add_tracks! tries to use the credentials of the playlist owner, instead of the current user's credentials.

response = User.oauth_post(@owner.id, url, {}.to_json)

If the credentials for the users are not found, it will fall back to the first token.

Properly fixing it requires a breaking change, as you need to pass the user to the playlist, but this will fix it for most cases.

@shaicoleman shaicoleman changed the title Fallback for playlist.add_tracks! if no credentials for the playlist owner exist Fix for playlist.add_tracks! if no credentials for the playlist owner exist May 3, 2024
@shaicoleman shaicoleman force-pushed the playlist-add-tracks-token-fallback branch from 91b1856 to afdad1d Compare May 3, 2024 21:55
@guilhermesad
Copy link
Owner

Looks good, thanks!

@guilhermesad guilhermesad merged commit 3f34a12 into guilhermesad:master May 6, 2024
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants