#spotify web api wrapper design questions

22 messages · Page 1 of 1 (latest)

compact cliff
#
int main()
{
    spotipp::auth user("client id", "client secret");

    std::string url = user.get_auth_token_url();
    std::cout << "Please open the url -> " << url << "\n";

    user.grab_auth_token();
    std::cout << "Auth token: " << user.get_auth_token() << "\n";

    user.grab_access_token();
    std::cout << "Access token: " << user.get_access_token() << "\n";

    spotipp::fetch::track specific_track = spotipp::fetch::get_track_from_id(user.get_access_token(), "2YzHSCRkNrOJmmYZ0HPBJJ");

    std::cout << "track name: " << specific_track.name << "\n";
    std::cout << "track's album: " << specific_track.album_name << "\n";
    std::cout << "track's number in the album: " << specific_track.number << "\n";
    std::cout << "track's popularity for the artist: " << specific_track.popularity << "\n";


    spotipp::fetch::track current_song = user.get_current_track();


    return 0;
}
``` im not sure about the way im doing things with the spotipp::fetch, any comments?
icy stumpBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

compact cliff
#

the idea behind this way of fetching songs is because in spotify you can fetch songs without logging it thru a user, a much simpler logging method to get access to basic spotify web api features

sick viper
#

you probably also want to make it method of user, that just call fetch and pass his access token
also no error handling on all network resources, id recommend std::expected

#

common api, but you really need error handling on network

#

in real world program

#

off work i have non-published hex-chess app that have no any error handling, and also just getting server crash on game finish, so xD

compact cliff
#

The thing that conflicts me is that you can also do certain stuff with the spotify web api without logging in like a regular user, using the whole server callback and so on, but just with a spotify dashboard application, so i feel like this method would allow for more freedom to pass whatever access token you want, instead of being forced to use the class provided and whatever

#

i could aswell keep on providing it, and also provide a method like user.get_track_from_id

sick viper
#

like that yes, if you have circular dependency, somehow, then just use another cpp for that
just

spec_track user::fetch_track_by_id(id_type id_val) const
{
   return fetch::fetch(this->get_access(),id_val);
}
compact cliff
#

hmm

sick viper
compact cliff
#

damn right you are

sick viper
#

still, error handling, id recommend std::expected, or at least optional + last error
(last error (and errno) in general bad practice)

compact cliff
#

thanks for the ideas, really appreciate it

sick viper
#

if you want it to see real world*

compact cliff
#

i'll work on all this, thanks a lot man

icy stumpBOT
#

@compact cliff Has your question been resolved? If so, type !solved :)

compact cliff
#

!solve

icy stumpBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

compact cliff
#

!solved