trs-80 / WWW-Spotify

Perl wrapper for Spotify Web API
Other
5 stars 3 forks source link

Is there any example on how to really use it? #18

Open depesz opened 1 year ago

depesz commented 1 year ago

Hi. I'm trying to write cli tool to do some stuff in spotify, but I can't get it to work.

Even the first example from doc:

use WWW::Spotify;
my $spotify = WWW::Spotify->new();
my $result = $spotify->album('0sNOF9WDwhWunNAHPD3Baj');
print Dumper($result);

gives me error:

$VAR1 = '{
  "error": {
    "status": 401,
    "message": "No token provided"
  }
}';

I do have client id/secret from developer.spotify.com, but search in docs only found oauth_client_id and oauth_client_secret, and when i used them:

use WWW::Spotify;
my $spotify = WWW::Spotify->new();
$spotify->oauth_client_id('07394b9ae3824d3e840dc052786936cd');
$spotify->oauth_client_secret('........');
my $result = $spotify->album('0sNOF9WDwhWunNAHPD3Baj');
print Dumper($result);

I still got "No token provided"?

I know that as some point in time i will need to handle oauth to get access to read write access to playlists, but searching for stuff should work without it? Or should I bite the bullet and work with oauth. But in such case: how?

trs-80 commented 1 year ago

Can you try this again and add this immediately after creating $spotify

$spotify->force_client_auth(1);

trs-80 commented 1 year ago

@depesz oauth is managed by the module and Spotify changes which end points are behind it so please try the recommendation provided above and let me know if that resolves your issue.

depesz commented 1 year ago

I did:

use WWW::Spotify;
my $spotify = WWW::Spotify->new();
$spotify->oauth_client_id('07394b9ae3824d3e840dc052786936cd');
$spotify->oauth_client_secret('...');
$spotify->force_client_auth(1);
my $result = $spotify->search(
    'lana del rey' ,
    'artist' ,
    { limit => 15 , offset => 0 }
);
print Dumper($result);

And it seemed to work, as in: it shows me some results.

Which is great, but how can I make it get access (over oauth) to my own private playlists, or to modify playlists?

oalders commented 1 year ago

@depesz you might want to edit your secret out of that example?

depesz commented 1 year ago

Heh. Thanks @oalders . Also disabled the keys, just in case.