GithubHelp home page GithubHelp logo

calliostro / spotify-web-api-bundle Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 3.0 23 KB

Spotify Web API client for Symfony 5 or Symfony 6

License: MIT License

PHP 100.00%
api bundle php spotify symfony

spotify-web-api-bundle's People

Contributors

calliostro avatar yoanbernabeu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

spotify-web-api-bundle's Issues

Multi route for the callback

Hello,

in your doc we can have only one route to redirect : /callback

If i want divers request in divers route how i can make this ?

How to run a function with authorization

This extension seems to fully meet my needs but I don't understand how to make it work.

For a function with no user-related endpoint required, no problem (like search).

But how to run a function with authorization ?
With route "callback", I get my user information
but with a new route "about_me" with only "$this->api->me();", I get a 500 error (Unauthorized)

class SomeController extends AbstractController
{
    private $api;
    private $session;

    public function __construct(SpotifyWebAPI $api, Session $session)
    {
        $this->api = $api;
        $this->session = $session;
    }

    /**
     * @Route("/callback")
     */
    public function callbackFromSpotify(Request $request): Response
    {
        try {
            $this->session->requestAccessToken($request->query->get('code'));
        } catch (SpotifyWebAPIAuthException $e) {
            return $this->redirectToRoute('some_redirect');
        }

        $this->api->setAccessToken($this->session->getAccessToken());
        // $me = $this->api->me();
        $me = '';

        return new Response(var_export($me, false), 200, ['Content-Type' => 'text/plain']);
    }

    /**
     * @Route("/redirect", name="some_redirect")
     */
    public function redirectToSpotify(): Response
    {
        $options = [
            'scope' => [
                'user-read-email',
            ],
        ];

        return $this->redirect($this->session->getAuthorizeUrl($options));
    }

    /**
     * @Route("/about_me", name="about_me")
     */
    public function aboutMe(): Response
    {
        $me = $this->api->me();

        return new Response(var_export($me, false), 200, ['Content-Type' => 'text/plain']);
    }

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.