calliostro / spotify-web-api-bundle Goto Github PK
View Code? Open in Web Editor NEWSpotify Web API client for Symfony 5 or Symfony 6
License: MIT License
Spotify Web API client for Symfony 5 or Symfony 6
License: MIT License
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 ?
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']);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.